Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In this example, How can I punt the Legend INSIDE the graph. Because when I save the graph, only save the graph BUT not save the legend.

Expr1 = -2 p + 1
Expr2 = 2 p - 1
Expr3 = p - 1/2
Plot[{Expr1, Expr2, Expr3}, {p, 0, 1},
 BaseStyle -> AbsoluteThickness[4], 
 PlotLegends -> 
  LineLegend["Expressions", BaseStyle -> AbsoluteThickness[4]]]
Solve[Expr1 == Expr2, p]

Another question. How can I insert the solution in the las line, too INSIDE the graph?

Here you can see the result http://img534.imageshack.us/img534/8941/for0.png

share|improve this question
    
Strongly related: "Creating legends for plots with multiple lines?" –  Alexey Popkov Nov 9 '13 at 9:55
    
Also related: mathematica.stackexchange.com/q/34357/280 –  Alexey Popkov Nov 9 '13 at 10:00
    
How to position legends where you want them: mathematica.stackexchange.com/questions/7547/… –  Mike Honeychurch Nov 9 '13 at 21:37

3 Answers 3

up vote 2 down vote accepted

This is how to save the graph, legend and all:

saves

Another way would be to use Rasterize:

Rasterize[Plot[...]]

The legend and the graph is now one image.

share|improve this answer
    
I like this one, but I don´t know how to select legends and plot. The plot is easy, but I can´t select the 2 thing at same time. –  Mika Ike Nov 9 '13 at 11:24
1  
@MikaIke Why do you need to select them at the same time? If you save it this way, the plot and the legend will be saved together as if you had selected it as one picture. btw. I didn't include how to put the solution in, but I would've done it like b.gatessucks did it. –  Pickett Nov 9 '13 at 11:50
2  
@MikaIke you can drag the cursor over both the legend and the plot. Start slightly to the right of the legend, click down, drag over both until both are selected (they are semi-transparently colored), then release mouse button. –  Sjoerd C. de Vries Nov 9 '13 at 13:35

You can define :

sol = Solve[Expr1 == Expr2, p][[1, 1]] ;
plot = Plot[{Expr1, Expr2, Expr3}, {p, 0, 1}, 
        BaseStyle -> AbsoluteThickness[4], 
        PlotLegends -> Placed[LineLegend["Expressions", BaseStyle -> AbsoluteThickness[4]], {Left, Center}], 
        Epilog -> Inset[sol, {0.5, 0.5}]]

plot

and export with

Export["/tmp/plot.png", plot]
share|improve this answer
4  
+2 for code, -1 for the ugliest plot I've seen so far today! :) –  cormullion Nov 9 '13 at 10:05
1  
@cormullion You should have seen what I did yesterday at work ! –  b.gatessucks Nov 9 '13 at 10:09

Or you can use the full form position specification with Placed to position legend "inside" the graph and use Legended to put any additional legends.

Legended[Plot[{Expr1, Expr2, Expr3}, {p, 0, 1}, 
  BaseStyle -> AbsoluteThickness[4], 
  PlotLegends -> 
   Placed[LineLegend["Expressions", 
     BaseStyle -> AbsoluteThickness[4]], {1.05, 0.5}]], 
   Placed[First@First@Solve[Expr1 == Expr2, p], {0.5, 1}]]

legended graph

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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