如何在Matplotlib中更改图的轴,刻度和标签的颜色 [英] How to change the color of the axis, ticks and labels for a plot in matplotlib

查看:96
本文介绍了如何在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()]

这篇关于如何在Matplotlib中更改图的轴,刻度和标签的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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