I have created the picture displayed below, with the following line of code:

Colors = List[Brown, Red, Orange, Yellow, Green, Blue, Pink, Purple, Black];    
      Plot[Part[list, i, 2]*Prob[Part[list, i, 2]*n] /. {y -> a, 
         z -> Part[list, i, 3]}, {n, 0, 3}, 
       PlotStyle -> {Thick, Part[Colors, i]}], {i, Length[list]}], 
     PlotRange -> {All, {0, 1.2}}]

The array list just contains sum numbers of the form { {a,b,c}, {c,d,e}, ...} and Prob is just some function, with constants y and z which I specify in the above. There are a few questions I have concerning this code:

-Note that the axis of the graph appears to lie above zero. I would like to make a graph with its x axis really at y=0. How to do this?

-I would like to give every graph in the picture a different label, which is stored in Part[list, i,2]. However, I have two problems: PlotLegends gives an error and I only know how to include text between " ", not a number which is determined by the running of the do loop.

Any help is very much appreciated!

enter image description here

  • 1
    $\begingroup$ Regarding the axes look for AxesOrigin like Plot[Sin@x, {x, 0, 1}, AxesOrigin -> {0, .5}]. Regarding PlotLegends: are you on V9 or on V8? $\endgroup$ – Öskå Nov 21 '13 at 16:51
  • $\begingroup$ @Öskå Thanks, AxesOrigin works! I am on V8 at work and on V9 at home :) $\endgroup$ – Funzies Nov 21 '13 at 16:54
  • 1
    $\begingroup$ PlotLegends only works on V9. For the V8 you have to import PlotLegend (which is pretty ugly!) or use autoLegend from here $\endgroup$ – Öskå Nov 21 '13 at 16:57

You do not need to create the plots individually and then combine them with Show. You can specify the options as lists and one of the comments already tells you how to position the axes origin.

functions = {x, x^2};
styles = Thread[{Thick, {Red, Brown}}];
legends = Table["function " <> ToString[i], {i, 2}];
Plot[functions, {x, 0, 1}, PlotStyle -> styles, 
   PlotLegends -> legends, AxesOrigin -> {0, 0.6}]

enter image description here

  • $\begingroup$ Thanks, this was very useful. I have but one last question: if I use your method and I save the graphic, the legend is not included. How do I included it when I export the graph as a picture? $\endgroup$ – Funzies Nov 21 '13 at 20:43
  • $\begingroup$ @Funzies: Are you exporting by selecting only the graph and the using the menu commands or are you exporting with Export[FileNameJoin[{$TemporaryDirectory, "test.png"}], Plot[functions, {x, 0, 1}, PlotStyle -> styles, PlotLegends -> legends, AxesOrigin -> {0, 0.6}]]? $\endgroup$ – Hector Nov 22 '13 at 13:20

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.