如何更改 matplotlib 中绘图的轴、刻度和标签的颜色
问题描述:
我想更改轴的颜色,以及我使用 matplotlib 和 PyQt 绘制的绘图的刻度和值标签.
I'd like to Change the color of the axis, as well as ticks and value-labels for a plot I did using matplotlib and PyQt.
有什么想法吗?
答
举一个简单的例子(使用比可能重复的问题更简洁的方法):
As a quick example (using a slightly cleaner method than the potentially duplicate question):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(10))
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.spines['bottom'].set_color('red')
ax.spines['top'].set_color('red')
ax.xaxis.label.set_color('red')
ax.tick_params(axis='x', colors='red')
plt.show()
[t.set_color('red') for t in ax.xaxis.get_ticklines()]
[t.set_color('red') for t in ax.xaxis.get_ticklabels()]