Matplotlib:更改轴的颜色

Matplotlib:更改轴的颜色,matplotlib,colors,Matplotlib,Colors,是否有方法更改matplotlib中轴(而不是刻度)的颜色?我一直在看Axis、Axis和Artist的文档,但没有运气;matplotlib库也没有提示。 有什么想法吗?请注意,我就是这样设法让它工作的: fig = pylab.figure() ax = fig.add_subplot(1, 1, 1) for child in ax.get_children(): if isinstance(child, matplotlib.spines.Spine): chi

是否有方法更改matplotlib中轴(而不是刻度)的颜色?我一直在看Axis、Axis和Artist的文档,但没有运气;matplotlib库也没有提示。
有什么想法吗?

请注意,我就是这样设法让它工作的:

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')

使用图形时,可以使用以下工具轻松更改脊椎颜色:

ax.spines['bottom'].set_color('#dddddd')
ax.spines['top'].set_color('#dddddd') 
ax.spines['right'].set_color('red')
ax.spines['left'].set_color('red')
使用以下命令仅更改记号:

  • which=“both”
    更改主刻度和次刻度颜色
ax.勾选参数(轴='x',颜色='red')
ax.勾选参数(轴为y,颜色为红色)
并执行以下操作以仅更改标签:

ax.yaxis.label.set_color('red')
ax.xaxis.label.set_color('red')
最后是标题:

ax.title.set_color('red')

ax.yaxis.label参数(axis='x',colors='red')
似乎会同时更改记号和标签的颜色…是否可以使用
ax.yaxis.label。设置颜色('grey')
,这样只有从
y1
y2
的记号才会更改颜色,其他点保持不变?知道如何更改要分散的点的颜色吗?@FaCoffee您可以通过调用
set\u ticklabels()
并传递
kwarg
颜色来设置记号标签颜色,而不受记号颜色的影响。像这样:
ax.xaxis.set_ticklebels([0.0,0.2,0.4,0.6,0.8,1.0],color='k')
@Jonathan的评论对我很有用。关键是要使用
colors
参数,而不是
color
参数(注意
s
)。Matplotlib还有一个允许临时更改rc参数的工具@joelostblom。我在浏览器和jupyter笔记本上使用了深色背景。一条线完成了全部工作。从上下文文档:
导入matplotlib.pyplot作为plt plt.style.use('dark_background')