3
$\begingroup$

Sometimes I like to display two plots right next to each other, so I can see all the important information at once.

For example, I have a plot with 5 lines, and I want to have a plot of only 2 of those lines right next to it.

Solutions I found with GraphicsRow etc often cut off parts of my plots, make the plots smaller, and when I try to readjust them, it just becomes worse. Like this for example:

GraphicsRow[{ListPlot[{table1,table2}, Joined -> True, 
ImageSize -> 200, ImagePadding -> {{Automatic, 10}, {Automatic, 10}}], 
ListPlot[{table1}, PlotLegends -> Automatic, Joined -> True, ImageSize -> 200, 
ImagePadding -> {{Automatic, 10}, {Automatic, 10}}]},
Spacings -> Scaled[0.2]]

I keep thinking there has to be an easier way that does not require so much finetuning. The outcome does not have to be very polished, as long as the plots are easily visible (like the default plot size that ListPlot produces).

Bonus points for keeping the colors the same for the same lines across the two plots.

$\endgroup$
5
  • $\begingroup$ If you don't want the plots to become smaller, add //Style[#,ImageSizeMulpliers-> {1,1}]& after your code. See here $\endgroup$
    – andre314
    Commented May 21, 2020 at 13:00
  • 1
    $\begingroup$ Why not gives examples and show what you tried? Otherwise, you asking people to do things from scratch. Also this way the answers will use the same plots you have. There are many ways to do these things. That is why having actual examples eliminates lots of guess work. $\endgroup$
    – Nasser
    Commented May 21, 2020 at 13:00
  • $\begingroup$ Well, because what I tried didn't work at all and I don't want a slightly improved version of what I tried, but I want to see if there is a better way to do this in general. $\endgroup$
    – fifaltra
    Commented May 21, 2020 at 13:05
  • $\begingroup$ But you still did not show what table1 and table2 is. So you asking someone to make up these themselves. Why not provide these as well? If it not too much work for you. $\endgroup$
    – Nasser
    Commented May 21, 2020 at 13:14
  • $\begingroup$ It's a general question.. Just take table1={{0,1},{1,2}} and table2={{0,1},{1,2.2}} $\endgroup$
    – fifaltra
    Commented May 21, 2020 at 13:16

2 Answers 2

7
$\begingroup$

This doesn't seem like a lot of fine tuning:

table1 = {{0, 1}, {1, 2}};
table2 = {{0, 1}, {1, 2.2}};
GraphicsRow[{ListLinePlot[{table1, table2}], ListLinePlot[{table1}]}]

enter image description here

To have the axes the same, you need to specify the range over which the plots are drawn. This uses the function PlotRange:

GraphicsRow[{ListLinePlot[{table1, table2}, PlotRange -> {All, {0, 2.5}}], 
             ListLinePlot[{table1}, PlotRange -> {All, {0, 2.5}}]}]
$\endgroup$
10
  • $\begingroup$ The axis labels on the left are cut off already... If we have something longer there, like 0.0001, it's going to get worse.. $\endgroup$
    – fifaltra
    Commented May 22, 2020 at 2:22
  • 2
    $\begingroup$ I used the data you suggested. If you wanted different plots then you should have given the data, as Nasser suggested. If you want to specify the range of axes, use PlotRange. $\endgroup$
    – bill s
    Commented May 22, 2020 at 2:54
  • $\begingroup$ I tried to express in my question that I would like something that does not crop the plots or changes the sizes in unpredictable ways. All the answers I found so far said to fiddle around with ImagePadding etc which is exactly what I would like to avoid, as I want to plot many things and having to manually adjust Padding etc every time takes too long. I'm sorry if that was unclear from my question. $\endgroup$
    – fifaltra
    Commented May 22, 2020 at 3:04
  • 3
    $\begingroup$ You said in your post: "The outcome does not have to be very polished, as long as the plots are easily visible" It seems to me that just using GraphicsRow, without all the fiddly bits, leaves plots that are clearly visible... $\endgroup$
    – bill s
    Commented May 22, 2020 at 3:36
  • 1
    $\begingroup$ It is not "cropping the plots" it is plotting each function over PlotRange->All (the default). If you want a different plotrange, then specify it. Do you expect Mathematica to read your mind? I showed you how to do it above. $\endgroup$
    – bill s
    Commented May 22, 2020 at 14:53
-2
$\begingroup$

In the end, I found that using Print does the trick.

Print[ListPlot[...,ImageSize->Medium]," ",ListPlot[...,ImageSize->Medium]]

I had hoped there is maybe a nicer way, but that's the best I found.

$\endgroup$
3
  • $\begingroup$ Why not Grid? Or PlotGrid? $\endgroup$ Commented May 21, 2020 at 18:45
  • $\begingroup$ PlotGrid looks interesting, but if I see this correctly, it only works if either x- or y-axis are the same for both plots? But for that case it looks good, thanks for the suggestion. $\endgroup$
    – fifaltra
    Commented May 22, 2020 at 2:27
  • $\begingroup$ not necessarily does that need to be so, you can force the display of the ticks labels and related items. $\endgroup$ Commented May 22, 2020 at 2:32

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