3
$\begingroup$

Is it possible to move the first plot in show to the front without changing which plot we inherit the options from?

The problem is that if I want a certain plot to go in front I cannot use it to inherit the options from.


While writing I thought of the following solution. I can include the plot twice. Once as the first argument and again later. Is this the best solution?

$\endgroup$
4
  • 2
    $\begingroup$ Does it work for you Show[otherPlots.., Graphics[##], ##2]& @@ thePlot ? $\endgroup$ – Kuba Dec 3 '19 at 13:01
  • $\begingroup$ I'd try Show[plot1, plot2,..., Options[plot2]], but in both my and @Kuba's suggestions, if there is an option in the first plot that is not explicitly overridden by the options, then the option from the first plot will be used. $\endgroup$ – Michael E2 Dec 3 '19 at 13:45
  • 1
    $\begingroup$ If the result of Show looks the way you want it to, I would say your solution of giving one of the plots as both first and last argument is a good solution even if it it not the best solution. I take an engineering view of things; if a solution works without any unwelcome side effects, use it and don't worry about what is best. $\endgroup$ – m_goldberg Dec 3 '19 at 13:46
  • $\begingroup$ You can also do Show[plot1, plot2, plot2[[2]]]. If you want to suppress the options from first plot entirely you can do Show[Graphics@First@plot1, plot2, plot2[[2]]]. $\endgroup$ – kglr Jan 7 '20 at 19:29
2
$\begingroup$

This is an interesting and common question so, to summarize the suggestions in comments:

  • @Kuba suggested:

    Show[otherPlots.., Graphics[##], ##2]& @@ thePlot
    
  • @Michael pointed out the following alternative:

    Show[plot1, plot2,..., Options[plot2]]
    

    but also mentioned that, if there is an option in the first plot that is not explicitly overridden by the options, then the option from the first plot will still be used.

  • As OP themselves mentioned in their question, a pragmatic approach suggested by @m_goldberg would be to simply have one of the plots both first and last in Show. Although perhaps inefficient, it will work and will not suffer from the stray option problem mentioned above.

$\endgroup$

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.