比例尺

说明应用于轴的比例变换,例如: log,symlog,logit。

比例尺示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.ticker import NullFormatter
  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. fig, axs = plt.subplots(2, 2, sharex=True)
  13. fig.subplots_adjust(left=0.08, right=0.98, wspace=0.3)
  14. # linear
  15. ax = axs[0, 0]
  16. ax.plot(x, y)
  17. ax.set_yscale('linear')
  18. ax.set_title('linear')
  19. ax.grid(True)
  20. # log
  21. ax = axs[0, 1]
  22. ax.plot(x, y)
  23. ax.set_yscale('log')
  24. ax.set_title('log')
  25. ax.grid(True)
  26. # symmetric log
  27. ax = axs[1, 1]
  28. ax.plot(x, y - y.mean())
  29. ax.set_yscale('symlog', linthreshy=0.02)
  30. ax.set_title('symlog')
  31. ax.grid(True)
  32. # logit
  33. ax = axs[1, 0]
  34. ax.plot(x, y)
  35. ax.set_yscale('logit')
  36. ax.set_title('logit')
  37. ax.grid(True)
  38. ax.yaxis.set_minor_formatter(NullFormatter())
  39. plt.show()

下载这个示例