|||
matplotlib.pyplot
supports not only linear axis scales, but also
logarithmic and logit scales. This is commonly used if data spans many orders
of magnitude. Changing the scale of an axis is easy:
plt.xscale('log')
An example of four plots with the same data and different scales for the y axis is shown below.
# Fixing random state for reproducibilitynp.random.seed(19680801)# make up some data in the open 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()# 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', linthresh=0.01)plt.title('symlog')plt.grid(True)# logitplt.subplot(224)plt.plot(x, y)plt.yscale('logit')plt.title('logit')plt.grid(True)# 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()
It is also possible to add your own scale, see Developer's guide for creating scales and transformations for details.
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-17 02:46
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社