SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Jorgen B. <jo...@po...> - 2004年02月16日 21:12:51
Hi, I just discovered matplotlib, it seems really cool & just what I have
been looking for.
I have a hopefully simple question: How can I change the font size and type
of the legend, and how can I remove the frame around the legend?
Thanks!
Jorgen
From: John H. <jdh...@ac...> - 2004年02月16日 23:20:29
>>>>> "Jorgen" == Jorgen Bergstrom <jo...@po...> writes:
 Jorgen> Hi, I just discovered matplotlib, it seems really cool &
 Jorgen> just what I have been looking for.
 Jorgen> I have a hopefully simple question: How can I change the
 Jorgen> font size and type of the legend, and how can I remove the
 Jorgen> frame around the legend?
Hi Jorgen,
Right now there are no nice functions to access the attributes of the
legend, though they will be easy to add. Basically, we need things
like
 leg = axes.get_legend() # return the axes Legend instance
and
 leg.get_texts() # return the Text instances in the legend
 leg.get_lines() # return the Line2D instances in the legend
 leg.get_patches()# return the Patch instance in the legend
 leg.get_frame() # return the Rectangle bounding box
 leg.draw_frame(False)
Here is some code that accesses the attributes directly. Not elegant,
but may get you what you want until proper accessor methods are added
Eg, in legend_demo, you could write
 texts = gca()._legend._texts
 set(texts, 'fontsize', 14) # use big fonts for the legend text
 set(texts, 'fontname, 'courier') # change the fontname
 box = gca()._legend._patch # the Rectangle instance containing the legend
 box.set_facecolor('b') # make the legend frame blue
 handles = gca()._legend._handles # the line / patch instance inside the legend
See the Line2D, Text and Patch classes in matplotlib.lines,
matplotlib.text and matplotlib.patches for information on what
attributes you can set for each of these types.
If you want to add the required methods to axes and legend to expose
these attributes, it is not hard -- send me a patch. Otherwise I'll
put it on my list of things to do.
JDH
From: John H. <jdh...@ac...> - 2004年02月17日 14:59:17
>>>>> "Jorgen" == Jorgen Bergstrom <jo...@po...> writes:
 Jorgen> Hi, I just discovered matplotlib, it seems really cool &
 Jorgen> just what I have been looking for.
 Jorgen> I have a hopefully simple question: How can I change the
 Jorgen> font size and type of the legend, and how can I remove the
 Jorgen> frame around the legend?
I put the required changes in matplotlib-0.50. See
examples/legend_demo.py for examples of how to change the legend font
properties, turn off the legend frame, control the legend line props,
etc...
JDH
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 によって変換されたページ (->オリジナル) /