程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The usage of set_xticks and set_xticklabels in Python (with code explanation)

編輯:Python

Set scale has two methods:

ax.set_xticks()設置刻度 ,matplotlibPut corresponding calibration range which position,By default, the scale is the scale label;

ax.set_xticklabels(),Can be any other type of value as the label,Can be assigned to the already set beforeset_xtick.

We illustrated by example in:

代碼解釋

import matplotlib.pyplot as plt
from numpy import *
random.seed(20)
x=random.randint(0,100,50)
fig,ax=plt.subplots(figsize=(12,8))
ax.plot(x,'kx--')
plt.show()

At this point we generate results for:

We add the code:

ticks = ax.set_xticks([0,20,40,60]) # 設置刻度


很明顯可以看出,We two pictureXAxis calibration has changed.

同樣的道理:

ticks = ax.set_xticks([0,20,40,60]) # 設置刻度
labels = ax.set_xticklabels(['one','two','three','four'],rotation = 30,fontsize = 'small') # 設置刻度標簽


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved