# Changing the legend and the style of plots that are displayed by Show?

I have a function two variables (which is not z t^2) that requires a lot of processing to plot. It would be very convenient for me if I could use the Plotstyle and Plotlegends options to make various 2D plots of projections of my function with Show, in a way that allows me to edit it without having to generate the plots again and wait a long time for it to be done.

I'm currently using something like the code below, illustrating my problem.

plottz =
Plot[
Evaluate @ Table[z t^2, {t, {.5, .6, .7, .8, 1}}], {z, 0, 5},
PlotStyle ->
{Dashing[{.01, .02}], Dashing[{.02, .02}], Dashing[{.04, .02}],
Dashing[{.06, .01}], Dashing[{5, .0}]},
PlotLegends ->
Placed[
LineLegend[
{"t = .5 h", "t = .6 h", "t = .7 h", "t = .8 h", "t = 1 h"},
LabelStyle -> 10],
{.3, .7}]];

Show[plottz, PlotRange -> All]

• something like: Show[plottz /. Join[Thread[ ColorData /@ Range -> ColorData["Rainbow"] /@ Subdivide], {AbsoluteThickness[_] -> AbsoluteThickness, LineLegend[a_, b_, opts : OptionsPattern[]] :> LineLegend[a /. AbsoluteThickness[_] -> AbsoluteThickness, b, LabelStyle -> 14, LegendMarkerSize -> {50, 10}, opts]}], PlotRange -> All]? – kglr Oct 1 '20 at 7:06

## 1 Answer

First I will put kglr's remarkable solution on record.

Show[plottz /.
Join[
Thread[
ColorData /@ Range -> ColorData["Rainbow"] /@ Subdivide],
{AbsoluteThickness[_] -> AbsoluteThickness,
LineLegend[a_, b_, opts : OptionsPattern[]] :>
LineLegend[a /. AbsoluteThickness[_] -> AbsoluteThickness, b,
LabelStyle -> 14, LegendMarkerSize -> {50, 10}, opts]}],
PlotRange -> All] IMO this is a solution the would occur only to someone with expertise far beyond mine. As a Mathematica user with more mundane skills, I would settle for a far simpler solution. I would not use Show at all. I would precompute a table of values for the function of two variables that is of interest and use ListLinePlot. Since the data being displayed has been precomputed, evaluating the plot many times will not be a problem. So one can edit the plot options freely and re-evaluate without worrying about performance.

data = With[{dz = 1}, Table[z t^2, {t, {.5, .6, .7, .8, 1}}, {z, 0, 5, dz}]];
ListLinePlot[data,
DataRange -> {0., 5.},
PlotStyle ->
{Dashing[{.01, .02}], Dashing[{.02, .02}], Dashing[{.04, .02}],
Dashing[{.06, .01}], Dashing[{5, .0}]},
PlotLegends ->
Placed[
LineLegend[{"t = .5 h", "t = .6 h", "t = .7 h", "t = .8 h", "t = 1 h"},
LabelStyle -> 10],
{.3, .7}]] And here is an edited version:

ListLinePlot[data,
DataRange -> {0., 5.},
PlotStyle  ->
({AbsoluteThickness, #} & /@
{Dashing[{.01, .02}], Dashing[{.02, .02}], Dashing[{.04, .02}],
Dashing[{.05, .02}], Dashing[{}]}),
PlotLegends ->
Placed[
LineLegend[{"t = .5 h", "t = .6 h", "t = .7 h", "t = .8 h", "t = 1 h"},
LabelStyle -> 12],
{.3, .7}]] A list plot is normally very fast, so that even if the OP has a function that evaluates slowly, once the data table is made plots made from the table should display quickly. This means that editing the plot's options will not be a performance issue.