matplotlib图形绘制个性化定制坐标轴刻度(刻度样式,文字刻度)

2,624 阅读1分钟

单个设置坐标轴的刻度和坐标值的样式,get_ticklabels()。

import matplotlib.pyplot as plt
import numpy as np
fig,ax=plt.subplots(figsize=(8,8),facecolor=(1.0,1.0,0.9421))

for ticklabel in ax.xaxis.get_ticklabels():    
    ticklabel.set_color("slateblue")    
    ticklabel.set_fontsize(18)    
    ticklabel.set_rotation(30)
ax.set_title("pic_show")

plt.plot()
plt.show()


自定义文字作为坐标轴标签matploylib.pyplot.xticks/(ax.set_xticks()\ax.set_xticks;abel\ax.get_xticks())

xticks()或许是涵盖最多的面向对象的方法的pyplot的API操作方法。

1、如果有返回值但是没有参数,等价于ax.get_xticks(),ax.get_xtickslabels()

2、没有返回值也没有参数等价于disable the xticks

3、有参数但是没有返回值,等价于设置坐标轴和坐标轴样式

import matplotlib.pyplot as plt
import numpy as np
from calendar import day_name

fig,ax=plt.subplots(figsize=(8,8),facecolor=(1.0,1.0,0.9421))

x=np.linspace(1,7,7)
y=2*xax.plot(x,y)

for ticklabel in ax.xaxis.get_ticklabels():    
    ticklabel.set_color("slateblue")    
    ticklabel.set_fontsize(18)    
    ticklabel.set_rotation(30)

plt.xticks(x,day_name[0:7])
ax.set_title("pic_show")

plt.plot()
plt.show()