Suppose that I am using Show to display several plots — for example, two plots and three contourplots.

Is there a nice way to add gridlines?


I realize I can just stick the gridlines into the first of the plot expressions, but sometimes when I'm changing functions around that gets confusing.

I thought Epilog would be a nice way to do this, but I don't think Gridlines works on the righthand side of an Epilog option.?

Perhaps the best option would be something like making a function that does exactly what I want. That is, a function that takes the plots I want to display and the gridlines I want as inputs and then combines them.

If it's the latter, then I don't need to see a solution — that is, it would be both above my current level and more than I need for now.

I am just curious if there is a simple, built-in way (other than putting gridlines into the first of the plot expressions)

Sorry for no minimal working example; I feel like the question can be understood/addressed without one.

  • 7
    $\begingroup$ why not Show[plot1,plot2, ..., plotn, GridLines->{{x1,x2,..., xk},{y1,y2,...,ym}}] (where the lists {x1,x2,..., xk} and {y1,y2,...,ym} specify the positions of horizontal and vertical gridlines, respectively)? $\endgroup$ – kglr Jan 15 '20 at 1:35
  • $\begingroup$ Thank you for the helpful comment. I had an "Epilog" in my show and I guess I was putting gridlines in the epilog. Whoops. $\endgroup$ – user106860 Jan 15 '20 at 19:52

You can add GridLines, or any other Graphics options, directly to Show:

  GridLines -> ...
  1. you can simply say GridLines->Automatic in the options in Show
  2. I always have grid lines in my plots, I feel any plot is incomplete without those wonderfully thin gridlines. So I have

SetOptions[#, GridLines -> Automatic] & /@ {Plot, ListPlot, ListLinePlot, PolarPlot, AudioPlot, BoxWhiskerChart, DistributionChart,DateListPlot,Histogram,ParametricPlot, ComplexListPlot,BarChart,DateHistogram,StreamPlot,VectorPlot};

in my init.m anyway, and then you don't have the problem in the first place.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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