2

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.

fifaltra
  • 339
  • 4
  • 11
  • If you don't want the plots to become smaller, add //Style[#,ImageSizeMulpliers-> {1,1}]& after your code. See here – andre314 May 21 '20 at 13:00
  • 1
    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. – Nasser May 21 '20 at 13:00
  • 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. – fifaltra May 21 '20 at 13:05
  • 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. – Nasser May 21 '20 at 13:14
  • It's a general question.. Just take table1={{0,1},{1,2}} and table2={{0,1},{1,2.2}} – fifaltra May 21 '20 at 13:16

2 Answers2

7

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}}]}]
bill s
  • 68,936
  • 4
  • 101
  • 191
  • 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.. – fifaltra May 22 '20 at 02:22
  • 2
    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. – bill s May 22 '20 at 02:54
  • 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. – fifaltra May 22 '20 at 03:04
  • 3
    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... – bill s May 22 '20 at 03:36
  • Except that it crops the tick labels, which for me is part of the plot, and a very crucial part. In the example it's not so bad because it just cuts a quarter of the 0 of 0.5, but having something with 3 or more digits there is not that uncommon. If there was an automatic way to tell GraphicsRow to not crop the plots I would be very happy with your answer. – fifaltra May 22 '20 at 05:23
  • 1
    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. – bill s May 22 '20 at 14:53
  • It's not about the plot range, it's about being able to read the tick labels (like the 0.5). – fifaltra May 23 '20 at 14:38
  • Did you grab the bottom right portion of the image and expand it? Then the 0.5 magically reappears, fully formed. It has to do with the size of your Notebook window (and/or your screen). – bill s May 23 '20 at 15:43
  • While that has worked with some plots, it didn't work with others (especially if the numbers are longer, like 0.0001 or something like that) Sometimes the plots even started to become smaller by resizing, which I did not understand. Maybe I should try making a minimal example where that happens to me and post a new question, I think this does not really make sense to try to get to the bottom of in comments. That was one of the reasons why GraphicsRow seemed a bit too fiddly for my use case, but that is probably more personal preference than anything else. – fifaltra May 26 '20 at 04:44
  • Often just a Grid is more suited than a GraphicsGrid see this answer https://mathematica.stackexchange.com/a/35205/45020. – Kvothe Dec 07 '22 at 19:46
-2

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.

fifaltra
  • 339
  • 4
  • 11