3
$\begingroup$

I have a figure which took some hours to create in Mathematica. I assigned it to a variable myplot, i.e., myplot = Plot[..]. Now I want to turn off my computer, even though the legends in this plot are not as good as I wish. I want to be able to change them later.

In Matlab I used to save the figure as a .fig file. Later I was able to open the .fig file and do any manipulation. How is this done in Mathematica? I dont want to spend hours and hours again to create the same figure with better legends, etc. My main concern is to be able to manipulate the legends of the figure without plotting it again with the new legend definitions.

Here is my try without any success:

Show[myplot, PlotLegends -> SwatchLegend[Placed[LineLegend[{Blue, Red, Green, Orange, Black, Cyan}, {"\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \\(0\)]\), \(c\),n]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \\(c\),m]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \\(c\),a]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \\(c\),h]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \\(c\),c]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \\(c\),\(\*SuperscriptBox[\(c\), \(*\)]\)]\)"}, LabelStyle -> 21, LegendFunction -> (Framed[#, RoundingRadius -> 2, FrameStyle -> LightGray] &)], {Left, Top}]]]

Here is the last lines of ctrl-shift+r

Inset[LineLegend[{RGBColor[0, 0, 1], RGBColor[1, 0, 0], RGBColor[0, 1, 0], RGBColor[1, 0.5, 0], GrayLevel[0], RGBColor[0, 1, 1]}, {"\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \(c\),n]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \(c\),m]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \(c\),a]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \(c\),h]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \(c\),c]\)", "\!\(\*SubsuperscriptBox[\(\*SubscriptBox[\(I\), \(0\)]\), \(c\),\(\*SuperscriptBox[\(c\), \(*\)]\)]\)"}, LabelStyle -> 21, 
LegendFunction -> (Framed[#1, RoundingRadius -> 2, FrameStyle -> GrayLevel[0.85]] & ), LegendLayout -> "Column"], Scaled[{0.99, 0.99}], 
ImageScaled[{1, 1}], BaseStyle -> {FontSize -> Larger}, FormatType -> StandardForm]}, AspectRatio -> 0.7, Axes -> True, AxesLabel -> {Style["t", FontSize -> 21], Style["\!\(\*SubscriptBox[\(I\), \(0\)]\)", FontSize -> 21]}, AxesOrigin -> {0, 0}, AxesStyle -> Arrowheads[0.03], BaseStyle -> 18, GridLines -> Automatic, GridLinesStyle -> GrayLevel[0.85], ImageSize -> {583., Automatic}, Method -> {}, PlotRange -> {{-0.5128185731395787, 0.9326363149439076}, {-0.00003110239778374659, 1.51579064969476}}, 

PlotRangeClipping -> True, PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}]

$\endgroup$
  • $\begingroup$ DumpSave would work for you? $\endgroup$ – Kuba Nov 4 '14 at 5:18
  • 1
    $\begingroup$ If you're working in a Notebook, you should be able to just save the notebook and reopen it. $\endgroup$ – Rick R Nov 4 '14 at 5:31
  • $\begingroup$ As long as you don't terminate your Plot[...] commands with a semicolon ;, the plots will appear in the frontend. This means that they physically reside in the frontend notebook, rather than the kernel, so when you save and quit, the plot will not be lost, and will still be there when you reopen the notebook. $\endgroup$ – DumpsterDoofus Nov 4 '14 at 15:04
  • $\begingroup$ @RickR and DumpsterDoofus. Yes I know that but I dont know how to do any operation that I want to a figure which is already there. I mean lets say I saved the notebook file and reopen it and I can see the figure right infront of me. Now what must I do to this figure so that its legend is say not at right top side but at left top side. There are 6 curves in the figure and I didnt like the color of one of the curves. I want to just change its color but I dont want to run the Plot operation once again with different parameters. I want to do this over an already created figure. How is it done? $\endgroup$ – Seyhmus Güngören Nov 4 '14 at 16:30
  • $\begingroup$ @Kuba thanks i think it will allow me to save the graph. I can reload it later but then how to manipulate it with some different figure parameters? $\endgroup$ – Seyhmus Güngören Nov 4 '14 at 16:39
4
$\begingroup$

You can actually change the plot even after it has been finished processing. Example

Plot[Evaluate[{Sin[x], Cos[x]}], {x, 0, 2 Pi}]

enter image description here

Place the cursor on top of the chart itself and press Ctrl-Shift-R You'll see the image convert to a Graphics evaluation. You can operate on this item. Let's say that we saved it under

g = Graphics[{{}, {}, {RGBColor[0.368417, 0.506779, 0.709798], 
     AbsoluteThickness[1.6], Opacity[1.], 
     Line[{{1.2822827157509358*...

I can later add new options to the Graphic. Example.

AppendTo[g, LabelStyle -> Directive[Blue, Bold]]

enter image description here

Or replace already existing options.

g /. Unevaluated[AxesLabel -> {_, _}] -> 
  Unevaluated[AxesLabel -> {"X Axis", "Y Axis"}]

enter image description here

You can of course change the command directly.

$\endgroup$
  • 1
    $\begingroup$ Note that if the LabelStyle option already appears in g, then appending another one to the list of options will have no effect. Use Show instead of Append. Show will replace the option. $\endgroup$ – Michael E2 Nov 4 '14 at 20:09
  • $\begingroup$ I have a plot right infront of me and I want to put its legend from top right to top left. In the edit I tried to use show with no success. I used myplot /.Unevaluated[PlotLegends -> {_}] -> Unevaluated[PlotLegends -> ..... but it also didnt work out. $\endgroup$ – Seyhmus Güngören Nov 4 '14 at 20:22
  • $\begingroup$ @SeyhmusGüngören, please press Ctrl-Shift-R twice on top of the graph. You'll see at the very end that there will be a Placed[xxx,{Top,Right}] -> Change to {Top,Left} $\endgroup$ – Zviovich Nov 4 '14 at 20:35
  • $\begingroup$ Thank you I was trying to it but there is no Placed at the output. It produces a very long output and at the end I dont have any term starting with Placed[..]. I add the end out output to the question as an edit. $\endgroup$ – Seyhmus Güngören Nov 4 '14 at 20:47
  • $\begingroup$ Okay finally I found it. It translated top right to Scaled[0.99,0.99]. $\endgroup$ – Seyhmus Güngören Nov 4 '14 at 21:39

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.