# Optimal image quality using Rasterize Function

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.

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

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