2
$\begingroup$

Based on previous posts about plotting two y axes on the same x axis, I wrote this function:

plotyy[x_, y1_, y2_] := Module[{xy1, xy2, p1, p2},
  xy1 = Table[{x[[i]], y1[[i]]}, {i, Length[x]}];
  xy2 = Table[{x[[i]], y2[[i]]}, {i, Length[x]}];
  p1 = ListLinePlot[xy1, ImagePadding -> 25, 
    Frame -> {True, True, False, False}, Axes -> False];
  p2 = ListLinePlot[xy2, ImagePadding -> 25, Axes -> False, 
    Frame -> {False, False, False, True}, 
    FrameTicks -> {None, None, None, All}, PlotStyle -> Red];
  Rasterize[Overlay[{p1, p2}], RasterSize -> 600, ImageSize -> 600]]

which takes three lists with the same length and plots y1 and y2 on x. I've values for image quality by RasterSize and ImageSize for using the plot in my report but for different plots it may need different values for those two options.

How can I can set the optimum values for RasterSize and ImageSize in my function?

Thanks, Amin.

$\endgroup$
1
$\begingroup$

Good to know how to auto-adjust the optimum value.

However, when auto-adjust value does not satisfy our demands, we could adjust the values, and see which is best.

Another Option is ImageResolution For Example:

plotyy[x_,y1_,y2_,a_,b_]:=Module[{xy1,xy2,p1,p2},xy1=Table[{x[[i]],y1[[i]]},    {i,Length[x]}];
xy2=Table[{x[[i]],y2[[i]]},{i,Length[x]}];
p1=ListLinePlot[xy1,ImagePadding->25,Frame->{True,True,False,False},Axes->False];
p2=ListLinePlot[xy2,ImagePadding->25,Axes->False,Frame->{False,False,False,True},FrameTicks->{None,None,None,All},PlotStyle->Red];
Rasterize[Overlay[{p1,p2}],RasterSize->500+a,ImageSize->600,ImageResolution->500+b]]

GraphicsGrid@Table[plotyy[{{1,1},{2,2}},{{3,3},{4,2}},{{2,2},{3,3}},a,b],{a,0,200,50},{b,0,200,50}]

of course, you could use Manipulate to adjust without too many pictures.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.