SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Neal B. <ndb...@gm...> - 2013年10月30日 14:14:36
I have a blue line plot and a green line plot. I'd like to add some figtext at 
the bottom, and I'd like the text colors to match the plot colors. So I'd have 
some text in blue and some in green.
figtext only allows one color
I could use 2 figtext, but then I have to manually find coordinate positions for 
the text. That's ugly.
It would be nice if we had a TeX-like approach, where I could create a green 
text object and a blue text object, then assemble them by stacking boxes.
Any ideas?
From: Paul I. <pi...@be...> - 2013年10月30日 14:32:24
Hi Neal,
Neal Becker, on 2013年10月30日 10:14, wrote:
> I have a blue line plot and a green line plot. I'd like to add some figtext at 
> the bottom, and I'd like the text colors to match the plot colors. So I'd have 
> some text in blue and some in green.
> 
> figtext only allows one color
> 
> I could use 2 figtext, but then I have to manually find coordinate positions for 
> the text. That's ugly.
> 
> It would be nice if we had a TeX-like approach, where I could create a green 
> text object and a blue text object, then assemble them by stacking boxes.
You should be able to follow the approach I've taken here in
stacking the text bounding boxes together:
 https://github.com/matplotlib/matplotlib/issues/697
best,
-- 
 _
 / \
 A* \^ -
 ,./ _.`\\ / \
 / ,--.S \/ \
 / `"~,_ \ \
 __o ?
 _ \<,_ /:\
--(_)/-(_)----.../ | \
--------------.......J
Paul Ivanov
http://pirsquared.org
From: Scott L. <sl...@sp...> - 2013年10月30日 15:03:10
On Oct 30, 2013, at 10:14, Neal Becker <ndb...@gm...> wrote:
> I have a blue line plot and a green line plot. I'd like to add some figtext at 
> the bottom, and I'd like the text colors to match the plot colors. So I'd have 
> some text in blue and some in green.
> 
> figtext only allows one color
> 
> I could use 2 figtext, but then I have to manually find coordinate positions for 
> the text. That's ugly.
> 
> It would be nice if we had a TeX-like approach, where I could create a green 
> text object and a blue text object, then assemble them by stacking boxes.
> 
> Any ideas?
I'm not sure it's the best approach, but I've used HPacker (or VPacker if you want more than one line) to do this
from matplotlib.offsetbox import HPacker
from matplotlib.offsetbox import VPacker
from matplotlib.offsetbox import TextArea
from matplotlib.offsetbox import AnchoredOffsetbox
plot([1,2,3,4,5])
wloc = TextArea('WIND XYZ=()', textprops=dict(color="r", size=12))
sloc = TextArea('SOHO XYZ=()', textprops=dict(color="k", size=18))
txt1 = HPacker(children=[wloc, sloc], align="baseline", pad=0, sep=12)
txt2 = VPacker(children=[wloc, sloc], align="baseline", pad=0, sep=30)
bbox = AnchoredOffsetbox(loc=1.0, pad=0, borderpad=0,
 bbox_to_anchor=(0.8, 0.10),
 bbox_transform=gca().transAxes,
 child=txt1,
 frameon=False)
gca().add_artist(bbox)
bbox = AnchoredOffsetbox(loc=1.0, pad=0, borderpad=0,
 bbox_to_anchor=(0.4, 0.80),
 bbox_transform=gca().transAxes,
 child=txt2,
 frameon=False)
gca().add_artist(bbox)
From: Sterling S. <sm...@fu...> - 2013年10月30日 16:29:50
On Oct 30, 2013, at 7:47AM, Scott Lasley wrote:
> 
> On Oct 30, 2013, at 10:14, Neal Becker <ndb...@gm...> wrote:
> 
>> I have a blue line plot and a green line plot. I'd like to add some figtext at 
>> the bottom, and I'd like the text colors to match the plot colors. So I'd have 
>> some text in blue and some in green.
>> 
>> figtext only allows one color
>> 
>> I could use 2 figtext, but then I have to manually find coordinate positions for 
>> the text. That's ugly.
>> 
>> It would be nice if we had a TeX-like approach, where I could create a green 
>> text object and a blue text object, then assemble them by stacking boxes.
>> 
>> Any ideas?
> 
> I'm not sure it's the best approach, but I've used HPacker (or VPacker if you want more than one line) to do this
I have taken this approach as well. See part of my answer at http://stackoverflow.com/questions/17086847/box-around-text-in-matplotlib/17092777#17092777
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 によって変換されたページ (->オリジナル) /