matplotlib 更改轴的颜色

8nuwlpux  于 2023-05-18  发布在  其他
关注(0)|答案(4)|浏览(97)

在matplotlib中,有没有一种方法可以改变轴的颜色(而不是刻度线)?我一直在寻找轴,轴,艺术家的文档,但没有运气; matplotlib gallery也没有提示。你知道吗?

juzqafwq

juzqafwq1#

使用地物时,可以通过以下操作轻松更改书脊颜色:

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

kcugc4gi2#

您可以通过调整默认rc设置来实现这一点。

import matplotlib
from matplotlib import pyplot as plt

matplotlib.rc('axes',edgecolor='r')
plt.plot([0, 1], [0, 1])
plt.savefig('test.png')
svmlkihl

svmlkihl3#

为了记录在案,这是我如何设法使它工作:

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

n1bvdmb64#

全局设置所有轴的边颜色:

matplotlib.rcParams['axes.edgecolor'] = '#ff0000'

相关问题