简体   繁体   English

Python 图形 - 更改轴标记颜色和图例边框颜色

[英]Python graph- change axis marker colours and legend border colours

I'm using Python to plot a couple of graphs and I'm trying to change the formatting and essentially 'brand' the graph.我正在使用 Python 到 plot 几个图表,我正在尝试更改格式并基本上“品牌化”图表。 I've managed to change most things using pylab.rcParams[...], but I can't work out how to change the colour of the markers on the axes and the border around the legend.我已经设法使用 pylab.rcParams[...] 更改了大多数内容,但我无法弄清楚如何更改轴上标记的颜色和图例周围的边框。 Any help would be much appreciated.任何帮助将非常感激。 The line below is an example of the type of code I've been using to edit other parts.下面的行是我用来编辑其他部分的代码类型的示例。 Basically just lines taken from matplotlibrc, but I can't find them to change everything I want.基本上只是从 matplotlibrc 中获取的行,但我找不到它们来改变我想要的一切。

pylab.rcParams[axes.labelcolor' = '#031F73'

If you just want to use rcParams , the proper parameters are xticks.color and yticks.color .如果您只想使用rcParams ,正确的参数是xticks.coloryticks.color I can't seem to find a key for the legend frame color.我似乎找不到图例框架颜色的关键。 You can set that (along with the tick colors) programmatically though.不过,您可以通过编程方式设置它(连同刻度颜色)。

import pylab

pylab.plot([1,2,3],[4,5,6], label ='test')
lg = pylab.legend()
lg.get_frame().set_edgecolor('blue')
ax = pylab.axes()

for line in ax.yaxis.get_ticklines():
    line.set_color('blue')
for line in ax.xaxis.get_ticklines():
    line.set_color('blue')

for label in ax.yaxis.get_ticklabels():
    label.set_color('blue')
for label in ax.xaxis.get_ticklabels():
    label.set_color('blue')

pylab.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM