Pyplot 比例尺(Scales)

在不同的比例上创建图。这里显示了线性,对数,对称对数和对数标度。有关更多示例,请参阅库的“缩放”部分。

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.ticker import NullFormatter # useful for `logit` scale
  4. # Fixing random state for reproducibility
  5. np.random.seed(19680801)
  6. # make up some data in the interval ]0, 1[
  7. y = np.random.normal(loc=0.5, scale=0.4, size=1000)
  8. y = y[(y > 0) & (y < 1)]
  9. y.sort()
  10. x = np.arange(len(y))
  11. # plot with various axes scales
  12. plt.figure(1)
  13. # linear
  14. plt.subplot(221)
  15. plt.plot(x, y)
  16. plt.yscale('linear')
  17. plt.title('linear')
  18. plt.grid(True)
  19. # log
  20. plt.subplot(222)
  21. plt.plot(x, y)
  22. plt.yscale('log')
  23. plt.title('log')
  24. plt.grid(True)
  25. # symmetric log
  26. plt.subplot(223)
  27. plt.plot(x, y - y.mean())
  28. plt.yscale('symlog', linthreshy=0.01)
  29. plt.title('symlog')
  30. plt.grid(True)
  31. # logit
  32. plt.subplot(224)
  33. plt.plot(x, y)
  34. plt.yscale('logit')
  35. plt.title('logit')
  36. plt.grid(True)
  37. # Format the minor tick labels of the y-axis into empty strings with
  38. # `NullFormatter`, to avoid cumbering the axis with too many labels.
  39. plt.gca().yaxis.set_minor_formatter(NullFormatter())
  40. # Adjust the subplot layout, because the logit one may take more space
  41. # than usual, due to y-tick labels like "1 - 10^{-3}"
  42. plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25,
  43. wspace=0.35)
  44. plt.show()

Pyplot 比例尺示例

参考

此示例中显示了以下函数,方法,类和模块的使用:

  1. import matplotlib
  2. matplotlib.pyplot.subplot
  3. matplotlib.pyplot.subplots_adjust
  4. matplotlib.pyplot.gca
  5. matplotlib.pyplot.yscale
  6. matplotlib.ticker.NullFormatter
  7. matplotlib.axis.Axis.set_minor_formatter

下载这个示例