Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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]}];


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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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