Matplotlib:着色轴/刻度线标签 [英] Matplotlib: coloring axis/tick labels

查看:137
本文介绍了Matplotlib:着色轴/刻度线标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一种颜色的y轴标签和刻度标签如何显示为红色?

How would one color y-axis label and tick labels in red?

例如,将"y-label"的值设置为0到40,将其涂成红色.

So for example the "y-label" and values 0 through 40, to be colored in red.

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)

fig = plt.figure()
ax = plt.subplot(111)
ax.set_ylabel("y-label")

for i in xrange(5):
    ax.plot(x, i * x, label='$y = %ix$' % i)

ax.legend()

plt.show()

推荐答案

  label = plt.ylabel("y-label")
  label.set_color("red")

类似地,您可以获取和修改刻度标签:

similarly, you can obtain and modify the tick labels:

[i.set_color("red") for i in plt.gca().get_xticklabels()]

这篇关于Matplotlib:着色轴/刻度线标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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