如何更改图例中字体的文本颜色? [英] How to change the text color of font in legend?

查看:93
本文介绍了如何更改图例中字体的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改matplotlib图中图例的字体颜色?

Is there a way to change the font color of the legend in a matplotlib plot?

特别是在图的背景较暗的情况下,图例中的默认黑色文本

Specially in occasions where the background of the plot is dark, the default black text in the legend is hard or impossible to read.

推荐答案

通话 Legend.get_texts()将在图例对象中获得Text对象的列表:

call Legend.get_texts() will get a list of Text object in the legend object:

import pylab as pl
pl.plot(randn(100), label="randn")
l = legend()
for text in l.get_texts():
    text.set_color("red")

这篇关于如何更改图例中字体的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆