有没有办法在matplotlib中更改轴的颜色(而不是刻度线)?我一直在浏览Axes,Axis和Artist的文档,但没有运气; matplotlib画廊也没有提示 . 任何的想法?
使用数字时,您可以使用以下方法轻松更改脊椎颜色:
ax.spines['bottom'].set_color('#dddddd') ax.spines['top'].set_color('#dddddd') ax.spines['right'].set_color('red') ax.spines['left'].set_color('red')
使用以下内容仅更改刻度:
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')
最后 Headers :
ax.title.set_color('red')
为了记录,这就是我设法让它工作的方式:
fig = pylab.figure() ax = fig.add_subplot(1, 1, 1) for child in ax.get_children(): if isinstance(child, matplotlib.spines.Spine): child.set_color('#dddddd')
您可以通过调整默认的rc设置来完成 .
import matplotlib from matplotlib import pyplot as plt matplotlib.rc('axes',edgecolor='r') plt.plot([0, 1], [0, 1]) plt.savefig('test.png')
3 回答
使用数字时,您可以使用以下方法轻松更改脊椎颜色:
使用以下内容仅更改刻度:
以下仅更改标签:
最后 Headers :
为了记录,这就是我设法让它工作的方式:
您可以通过调整默认的rc设置来完成 .