Matplotlib: coloring axis/tick labels

家住魔仙堡 提交于 2019-11-28 09:56:23
  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()]

The xlabel can be colorized when setting it,

ax.set_xlabel("x-label", color="red")

For setting the ticklabels' color, one may either use tick_params, which sets the ticklabels' as well as the ticks' color

ax.tick_params(axis='x', colors='red')

Alternatively, plt.setp can be used to only set the ticklabels' color, without changing the ticks' color.

plt.setp(ax.get_xticklabels(), color="red")

Note that for changing the properties on the y-axis, one can replace the x with a y in the above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!