SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Wolfgang K. <wke...@go...> - 2007年08月27日 15:05:40
Is there any way to display a legend in a second window or outside the plot?
thanks in advance
 Wolfgang
From: Bernhard V. <Ber...@de...> - 2007年08月29日 08:57:12
Here's a legend function which allows you to specify loc='outer right'. The
part for 'outer left' doesn't work. It basically wrappes the
pylab.legendmethod, it rescales the plot and sets the location of the
legend to
coordinates outside of the current axes.
def legend(*args, **kwargs):
 """
 Overwrites the pylab legend function.
 It adds another location identfier 'outer right'
 which locates the legend on the right side of the plot
 The args and kwargs are forwarded to the pylab legend function
 """
 if kwargs.has_key('loc'):
 loc = kwargs['loc']
 loc = loc.split()
 if loc[0] == 'outer':
 # make a legend with out the location
 # remove the location setting from the kwargs
 kwargs.pop('loc')
 leg = pylab.legend(loc=(0,0), *args, **kwargs)
 frame = leg.get_frame()
 currentAxes = pylab.gca()
 currentAxesPos = currentAxes.get_position()
 # scale plot by the part which is taken by the legend
 plotScaling = frame.get_width()/currentAxesPos[2]
 if loc[1] == 'right':
 # scale the plot
 currentAxes.set_position((currentAxesPos[0],
currentAxesPos[1],
 currentAxesPos[2] *
(1-plotScaling),
 currentAxesPos[3]))
 # set x and y coordinates of legend
 leg._loc = (1 + leg.axespad, 1 - frame.get_height())
 # doesn't work
 #if loc[1] == 'left':
 # # scale the plot
 # currentAxes.set_position((currentAxesPos[0] +
frame.get_width(),
 # currentAxesPos[1],
 # currentAxesPos[2] *
(1-plotScaling),
 # currentAxesPos[3]))
 # # set x and y coordinates of legend
 # leg._loc = (1 -.05 - leg.axespad - frame.get_width(), 1 -
frame.get_height())
 pylab.draw_if_interactive()
 return leg
 return pylab.legend(*args, **kwargs)
Cheers! Bernhard
On 8/27/07, Wolfgang Kerzendorf <wke...@go...> wrote:
>
> Is there any way to display a legend in a second window or outside the
> plot?
> thanks in advance
> Wolfgang
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /