Matplotlib:更改轴的颜色 [英] Matplotlib: Changing the color of an axis

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

问题描述

有没有办法改变一个轴的颜色(不是ticks)在matplotlib?我一直在寻找Axes,Axis和Artist的文档,但没有运气; matplotlib库也没有提示。
任何想法?

Is there a way to change the color of an axis (not the ticks) in matplotlib? I have been looking through the docs for Axes, Axis, and Artist, but no luck; the matplotlib gallery also has no hint. Any idea?

推荐答案

使用图形时,可以轻松地更改脊柱颜色:

When using figures, you can easily change the spine color with:

ax.spines['bottom'].set_color('#dddddd')
ax.spines['top'].set_color('#dddddd') 
ax.spines['right'].set_color('red')
ax.spines['left'].set_color('red')

使用以下命令只更改刻度:

Use the following to change only the ticks:

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

并且以下仅更改标签:

ax.yaxis.label.set_color('red')
ax.xaxis.label.set_color('red')

最后是标题:

ax.title.set_color('red')

这篇关于Matplotlib:更改轴的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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