I have two datasets on a ListPlot
, but they have very different ranges. What I want to have is something like this.
I also want to know if it is possible to frame the plot legends and give a ubication on the plot just like in the figure.
I have two datasets on a ListPlot
, but they have very different ranges. What I want to have is something like this.
I also want to know if it is possible to frame the plot legends and give a ubication on the plot just like in the figure.
dat1 = RandomReal[100, 100];
dat2 = RandomReal[2000, 100];
ip = {{30, 50}, {30, 25}};
plot1 = ListLinePlot[dat1, ImagePadding -> ip, ImageSize -> 500,
PlotStyle -> Red, Frame -> {True, True, True, False},
FrameStyle -> {Black, Red, Black, Black}];
plot2 = ListLinePlot[dat2, ImageSize -> 500, PlotStyle -> Blue,
ImagePadding -> ip, Frame -> {False, False, False, True},
FrameTicks -> {{False, All}, {False, False}}, FrameStyle -> Blue];
legend = SwatchLegend[{Red, Blue}, {"red", "blue"}]
Legended[Overlay[{plot1, plot2}], Placed[legend, Bottom]]
This is a simple application I know, which corrects a formatting issue with the axes. However, there are many similar questions with much more complete answers if you are looking for complexities and details.
If you want the legends to be in the charts, a crude solution is this.
dat1 = RandomReal[100, 100];
dat2 = RandomReal[2000, 100];
ip = {{30, 50}, {30, 25}};
plot1 = ListLinePlot[dat1, ImagePadding -> ip, ImageSize -> 500,
PlotStyle -> Red, Frame -> {True, True, True, False},
FrameStyle -> {Black, Red, Black, Black}
, PlotLegends ->
Placed[LineLegend[{"plot 1"}, LegendFunction -> Frame,
LegendMarkerSize -> {{55, 10}}], {0.8, 0.2}]];
plot2 = ListLinePlot[dat2, ImageSize -> 500, PlotStyle -> Blue,
ImagePadding -> ip, Frame -> {False, False, False, True},
FrameTicks -> {{False, All}, {False, False}}, FrameStyle -> Blue
, PlotLegends ->
Placed[LineLegend[{"plot 2"}, LegendFunction -> Frame,
LegendMarkerSize -> {{55, 10}}], {0.8, 0.3}]];
Overlay[{plot1, plot2}]