legend font color

Is there a way to set the legend font color? I am plotting multiple sets of
data using different colors. I basically want to set each legend font color
the same as the corresponding data line color. Here is an example.

x = arange(0,10,0.1)
y1 = sin(x)
y2 = cos(x)

plot(x,y1,'r-',x,y2,'b--')

I want the legend font for y1 to be in red and the legend font for y2 to be
in blue.

Can anybody help? Thanks.

···

--
View this message in context: http://old.nabble.com/legend-font-color-tp29741260p29741260.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

It does this automatically.

ted

···

On 17 September 2010 19:13, musik <xi.xiaoxiang@…287…> wrote:

Is there a way to set the legend font color? I am plotting multiple sets of

data using different colors. I basically want to set each legend font color

the same as the corresponding data line color. Here is an example.

x = arange(0,10,0.1)

y1 = sin(x)

y2 = cos(x)

plot(x,y1,‘r-’,x,y2,‘b–’)

I want the legend font for y1 to be in red and the legend font for y2 to be

in blue.

Can anybody help? Thanks.

View this message in context: http://old.nabble.com/legend-font-color-tp29741260p29741260.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


Start uncovering the many advantages of virtual appliances

and start using them to simplify application deployment and

accelerate your shift to cloud computing.

http://p.sf.net/sfu/novell-sfdev2dev


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

musik,

I am not aware of any easy way to control the font properties for each individual item in a legend box. I would suppose that it would be possible to obtain the list of Text objects from the legend object (after creating the legend object), and then modify their color properties based on the string that it contains. Note that I have never personally tried this.

As far as I can tell, the text for the legend elements are black by default. Note that you can set the font properties for all Text objects in a legend when creating the legend with the ‘prop’ kwarg.

I hope this helps,

Ben Root

···

On Fri, Sep 17, 2010 at 1:13 PM, musik <xi.xiaoxiang@…985…> wrote:

Is there a way to set the legend font color? I am plotting multiple sets of

data using different colors. I basically want to set each legend font color

the same as the corresponding data line color. Here is an example.

x = arange(0,10,0.1)

y1 = sin(x)

y2 = cos(x)

plot(x,y1,‘r-’,x,y2,‘b–’)

I want the legend font for y1 to be in red and the legend font for y2 to be

in blue.

Can anybody help? Thanks.

I misunderstood your question, musik. My apologies.

Ted

···

On 18 September 2010 02:15, Benjamin Root <ben.root@…1304…> wrote:

On Fri, Sep 17, 2010 at 1:13 PM, musik <xi.xiaoxiang@…287…> wrote:

Is there a way to set the legend font color? I am plotting multiple sets of

data using different colors. I basically want to set each legend font color

the same as the corresponding data line color. Here is an example.

x = arange(0,10,0.1)

y1 = sin(x)

y2 = cos(x)

plot(x,y1,‘r-’,x,y2,‘b–’)

I want the legend font for y1 to be in red and the legend font for y2 to be

in blue.

Can anybody help? Thanks.

musik,

I am not aware of any easy way to control the font properties for each individual item in a legend box. I would suppose that it would be possible to obtain the list of Text objects from the legend object (after creating the legend object), and then modify their color properties based on the string that it contains. Note that I have never personally tried this.

As far as I can tell, the text for the legend elements are black by default. Note that you can set the font properties for all Text objects in a legend when creating the legend with the ‘prop’ kwarg.

I hope this helps,

Ben Root


Start uncovering the many advantages of virtual appliances

and start using them to simplify application deployment and

accelerate your shift to cloud computing.

http://p.sf.net/sfu/novell-sfdev2dev


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I initially read like Ted did :slight_smile: Here is a simple demonstration of Ben’s explanation:

x = np.arange(0,10,0.1)

y1 = np.sin(x)

y2 = np.cos(x)

fig = plt.figure()

ax = fig.add_subplot(111)

p1, = ax.plot(x, y1, label=“y1”)

p2, = ax.plot(x, y2, label=“y2”)

leg = ax.legend()

text1, text2 = leg.get_texts()

this part can be turned into a loop depends on the number of text objects

text1.set_color(p1.get_color())

text2.set_color(p2.get_color())

plt.show()

···

On Fri, Sep 17, 2010 at 1:13 PM, musik <xi.xiaoxiang@…287…> wrote:

Is there a way to set the legend font color? I am plotting multiple sets of

data using different colors. I basically want to set each legend font color

the same as the corresponding data line color. Here is an example.

x = arange(0,10,0.1)

y1 = sin(x)

y2 = cos(x)

plot(x,y1,‘r-’,x,y2,‘b–’)

I want the legend font for y1 to be in red and the legend font for y2 to be

in blue.

Can anybody help? Thanks.


Gökhan

That works perfectly. Thank you all so much!

Gökhan SEVER-2 wrote:

···

On Fri, Sep 17, 2010 at 1:13 PM, musik <xi.xiaoxiang@...287...> wrote:

Is there a way to set the legend font color? I am plotting multiple sets
of
data using different colors. I basically want to set each legend font
color
the same as the corresponding data line color. Here is an example.

x = arange(0,10,0.1)
y1 = sin(x)
y2 = cos(x)

plot(x,y1,'r-',x,y2,'b--')

I want the legend font for y1 to be in red and the legend font for y2 to
be
in blue.

Can anybody help? Thanks.

I initially read like Ted did :slight_smile: Here is a simple demonstration of Ben's
explanation:

x = np.arange(0,10,0.1)
y1 = np.sin(x)
y2 = np.cos(x)
fig = plt.figure()
ax = fig.add_subplot(111)
p1, = ax.plot(x, y1, label="y1")
p2, = ax.plot(x, y2, label="y2")
leg = ax.legend()
text1, text2 = leg.get_texts()
# this part can be turned into a loop depends on the number of text
objects
text1.set_color(p1.get_color())
text2.set_color(p2.get_color())
plt.show()

--
Gökhan

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://old.nabble.com/legend-font-color-tp29741260p29747823.html
Sent from the matplotlib - users mailing list archive at Nabble.com.