Message Boards Message Boards

1
|
30350 Views
|
11 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Include Epilog Line in PlotLegends?

function = {x, x^2};

time = {10, 5};
TimeUnit="Seconds"

MapThread[Plot[#1, {x, 0, #2},
Epilog -> {Directive[{Thin, Black, Dotted}],
Line[{{2, 0}, {2, #1 /. x -> 2}}]}] &, {function, time}]
I need to be able to include both a description of the function and the epilog line in the plot legend for each pair of functions and time. It seems like I am only able to do one or the other, and I couldn't find a way to get Legended to work.

Also, it would be nice to be able to include exponents in my strings for the plot legend, or at least know how to format the numbers and strings in the proper format so they appear in the correct order in the legend:
PlotLegends -> {"Irr. Time= " #2 " " <> TimeUnit <> "; Max Act: " #1 /. x -> 2 " \[Mu]Ci"}
Mathematica is multiplying the actual values together (which makes sense), but if I try to correct this by passing the values in as strings and joining them together to keep them in order, the scientific expressions/exponents get distrorted when they do appear (the actual code is much more complex than this). Any help would be greatly appreciated.
POSTED BY: Robbie Haffner
11 Replies
Posted 9 years ago

Hi use this:

PlotLegends -> 
 Placed[LineLegend[c,LegendLabel -> "Solar Concentration"], {Scaled[{0.5, 0.5}], {0.5, 0.5}}]

this method published by " Priyan Fernando" and You need to change the numbers however.

goodluck

POSTED BY: Hadi Tokme

To use plots for publication, I right click on the Mathematica plot, and select save graphic as adobe pdf files, which are high resolution files. Then to prepare them for publication, I open the pdf files in Adobe Photoshop with the resolution set higher than the default of 300 pixels per inch on my computer. I usually use 600 or 1200. Then I do my alterations, this results in layers that I save as psd files, in case I have to redo them, which is often the case. To make the output file, I flatten the image into a single layer and then use save as tif with LWZ compression which makes files as small as jpg files but are lossless and much better quality for line drawings especially, and which most publishers accept, indeed, many prefer. This procedure results in small files with quality as good as needed. I am sure there are lots of other way of creating good graphics, but the way I do it is similar to what a graphics artist would choose, at least some of them.

POSTED BY: Carl Wesolowski

You're welcome, Robbie.

As for the file format, if it is just for posting, like in the Community, I usually use Mac built-in screen capture app which automatically saves in png format with the default resolution(which depends on the monitor, ex: doubled in retina display). I usually trash them once posted. I don't use JPG since it is in nature of lossy compression. I would recommend to use PNG or BMP which has lossless compression or without any compression to avoid aliasing.

POSTED BY: MinHsuan Peng

Look at this example. PlotLegends allows you to use full-blown customized legends wrapped with Placed to specify where to put.

    Plot[1, {x, 0, 1}, Epilog -> {Directive[Thick, Black, Dashed], Line[{{0.5, 1}, {0.5, 0}}]}, 
    PlotLegends -> {Placed[LineLegend[1, {"test"}], Right], 
       Placed[LineLegend[{Directive[Thick, Black, Dashed]}, {"epilog"}], Right]}]

CustomizedLegends

POSTED BY: MinHsuan Peng

MinHsuan, That's probably the most basic solution that I could have asked for. Thank you for the help. I suppose I actually need to sit down and finish my making my results look nice.

While we're at it, does anyone really have any preference on what file format to export pictures at? I've noticed that bumping the resolution above 1500 or so really eats up my ram, but I am also kind of struggling with lack of clarity in my numbers (especially my axes) when the resolution is set any lower than 1000. I think I'm using .png but have experimented with .jpg

It's not that big of a deal, but I guess knowing what's a little more common would be nice.

POSTED BY: Robbie Haffner
Mr. Haffner,

I tried to answer the question of "how to" with "there isn't an automatic way".

If you want a legend that includes both lines in the Plot and lines from the Epilog,
build a LineLegend and use Inset to place it to the side of the main plot.
Or you could use Line and Text primitives to create a legend-like Graphic that
you Inset next to the main plot.  You might need to experiment with margins
or padding to have room for the hand-built legend.

Bruce
POSTED BY: Bruce Miller
No, these do not answer the question. I am aware of how to include lines from the plot into the legend, but what I need to do is add a third entry of the epilog line into the legend to point out a specific spot. That way anybody who looks at the graph knows exactly what the epilog line and the functions represent. Does that make sense?

My second problem was resolved, however. The TraditionalForm change worked like a charm for my exponents, thank you.
POSTED BY: Robbie Haffner
The short answer to the original question is that only lines in the main plot are passed to the legends code.
The additions with Epilog are added to the plot after the main plot is built.  The combination is displayed.
POSTED BY: Bruce Miller
Posted 11 years ago
Bruce Miller,
I was uncertain regarding the nature of the question, hence my post. I merely wished to illustrate how to pass things to legend and how to customize.
POSTED BY: Mark Dooris
Posted 11 years ago
If your aim is to plot multiple curves and use a legend for each with:
f[x_] := {x, x^2};
for example. Here are some approaches  (note in all cases Evaluate[f] is important):
Plot[Evaluate[f[x]], {x, 0, 1},PlotLegends -> LineLegend["Expressions"]]



or you can customize, e.g.
lg = LineLegend[Automatic, TraditionalForm /@ f[x],LegendFunction -> (Labeled[Framed[#], "Linear and Quadratics",Top] &)];

Plot[Evaluate[f[u]], {u, 0, 1}, PlotLegends -> lg]

POSTED BY: Mark Dooris
I have below the same code as you with more annotations. I don't have PlotLegends in Mma7, therefore I use "Inset". Hope this helps.
 (* iabraham, Mathematica 7.0.1.0, Win-7-64b *)
 Clear["Global`*"]
 
 function = {x, x^2};
 time = {10, 5};
 TimeUnit="Seconds";
 MapThread[Plot[#1, {x, 0, #2},
 Epilog -> {(* Start Epilog *)
 Directive[{Thin, Black, Dotted}], Line[{{2, 0}, {2, #1 /. x -> 2}}], (* Draw the vertical line *)
(* Below is the new code to include the function into the plots *)
Inset[Style[StringJoin["f(x) = ", ToString[TraditionalForm[#1]](* CLose StringJoin *)],12],Scaled[{0.25,0.75}](* Close Inset *)]
(* Close Epilog *)}(* Close Plot *)]&, {function, time}(* Close MapThread *)]
POSTED BY: Isaac Abraham
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract