共計(jì) 1333 個(gè)字符,預(yù)計(jì)需要花費(fèi) 4 分鐘才能閱讀完成。
這篇文章主要介紹 matplotlib 如何實(shí)現(xiàn) scale 刻度,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
1.5. 對數(shù)或者其他非線性坐標(biāo)軸
使用 plt.xscal() 來改變坐標(biāo)軸的刻度
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter # useful for `logit` scale# Fixing random state for reproducibilitynp.random.seed(19680801)# make up some data in the interval ]0, 1[y = np.random.normal(loc=0.5, scale=0.4, size=1000)
y = y[(y 0) (y 1)]
y.sort()
x = np.arange(len(y))# plot with various axes scalesplt.figure(1)# linearplt.subplot(221)
plt.plot(x, y)
plt.yscale(linear)
plt.title(linear)
plt.grid(True)# logplt.subplot(222)
plt.plot(x, y)
plt.yscale(log)
plt.title(log)
plt.grid(True)# symmetric logplt.subplot(223)
plt.plot(x, y - y.mean())
plt.yscale(symlog , linthreshy=0.01)
plt.title(symlog)
plt.grid(True)# logitplt.subplot(224)
plt.plot(x, y)
plt.yscale(logit)
plt.title(logit)
plt.grid(True)# Format the minor tick labels of the y-axis into empty strings with# `NullFormatter`, to avoid cumbering the axis with too many labels.plt.gca().yaxis.set_minor_formatter(NullFormatter())# Adjust the subplot layout, because the logit one may take more space# than usual, due to y-tick labels like 1 - 10^{-3} plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
wspace=0.35)
plt.show()
以上是“matplotlib 如何實(shí)現(xiàn) scale 刻度”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道!
正文完
發(fā)表至: 計(jì)算機(jī)運(yùn)維
2023-08-25