Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'plot legend and show' topicStudent Support Forum > General > "plot legend and show"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Forum Moderator
email me
10/17/99 06:20am

>>>I am trying to plot four lines, and fill in the area bounded below by two of them and above by two of them. I create three different plots, covering three abutting regions, so that the area between functions 1 and 3 is filled in the first, then the area between functions 1 and 4, and finally no area is filled. I then combine all three plots using show, and obtain a cohesive graph showing exactly what I want.
>>>The problem arises when I add a legend. It seems I cannot add a legend to the Show command. When I add a legend to the third plot, which is the rightmost, the legend appears in that plot, but disappears when combined in Show. How can I display a legend in the final graph?
>>Please provide a example of the code you are using. In
>>general, providing code that readers can evaluate and
>>test will increase the speed of a response.
>>Forum Moderator
>In the code I am using, the Legend disappears once the three plots are shown together. Since I used functions I've defined, I have simply replaced them with three simple functions. Upon doing this, the legend does not disappear, but rather it seems that the third plot has been placed below the first two, rather than to the right. Each one shows up properly, on its own. I'm sure that this is the same problem that I encountered. How do I fix the code so that the third plot appends to the right portion and the legend further to the right?
>plot1=FilledPlot[{-x+6, x, x^2},{x,0,1},Fills->{{{1,2},Hue[.7,.7,.7]}},PlotStyle->{RGBColor[0,0,1],RGBColor[0,1,0],RGBColor[1,0,0]}]
>(*This fills in the area between the first two functions from x=0 to x=1*)
>plot2=FilledPlot[{-x+6, x, x^2},{x,1,2},Fills->{{{1,3},Hue[.7,.7,.7]}},PlotStyle->RGBColor[0,0,1],RGBColor[0,1,0],RGBColor[1,0,0]}]
>(*This fills in the area between the first and third functions from x=1 to x=2*)
>(*When combined, this will show the area below the first function that is above both the second and third function*)
>plot3=Plot[{-x+6,x,x^2},{x,2,6},PlotStyle->RGBColor[0,0,1],RGBColor[0,1,0],RGBColor[1,0,0]},PlotLegend->{''f'',''g'',''h''},LegendPosition->{1,-.7},LegendTextSpace->.5,LegendLabel->''Test Funcs'',LegendLabelSpace->.5,LegendOrientation->Horizontal,LegendBackground->GrayLevel[.5]]
>(*This shows how the functions continue*)
>(*This merges all of the plots into one cohesive diagram. This is the only way I know how to fill in area above one function and below another. However, when I choose the Show function, the Legend that appears in plot3 disappears in the first example, and in this second example, it appears squashed, the combined plot now goes from x=-1 to x=2, not x=0 to x=6. It seems as though by including a legend, the entire graph was shrunk, and then for some reason, placed below the other two plots, rather than beside them*).


Try using ShowLegend with Legend arguments instead of Show.
E.g. Drop the Legend options from your plot3:

In[21]:= plot3=Plot[{-x+6,x,x^2},{x,2,6},

Create a combination plot using Show:

In[22]:= comboPlot=Show[plot1, plot2, plot3]

Use ShowLegend to add a legend to the combination plot:

In[23]:= ShowLegend[
comboPlot, {{{RGBColor[1,0,0],
StyleForm[f, TraditionalForm, FontSize -> 12]},
StyleForm[g, TraditionalForm, FontSize -> 12]},{RGBColor[0,0,1],
StyleForm[h, TraditionalForm, FontSize -> 12]}},

There are a number of Legend/ShowLegend examples at:

Tom Zeller
Forum Moderator

URL: ,

Subject (listing for 'plot legend and show')
Author Date Posted
plot legend and show randy silvers 09/28/99 2:25pm
Re: plot legend and show Forum Modera... 10/13/99 09:27am
Code Randy Silvers 10/17/99 06:13am
Re:Code Forum Modera... 10/17/99 06:20am
< Previous CommentHelp | Reply To Comment | Reply To Topic