演示Curvelinear网格2

自定义网格和记号行。

此示例演示如何通过在网格上应用转换,使用GridHelperCurve线性来定义自定义网格和注释行。作为打印上的演示,轴上将显示5x5矩阵。

Curvelinear网格2示例

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from mpl_toolkits.axisartist.grid_helper_curvelinear import \
  4. GridHelperCurveLinear
  5. from mpl_toolkits.axisartist.axislines import Subplot
  6. import mpl_toolkits.axisartist.angle_helper as angle_helper
  7. def curvelinear_test1(fig):
  8. """
  9. grid for custom transform.
  10. """
  11. def tr(x, y):
  12. sgn = np.sign(x)
  13. x, y = np.abs(np.asarray(x)), np.asarray(y)
  14. return sgn*x**.5, y
  15. def inv_tr(x, y):
  16. sgn = np.sign(x)
  17. x, y = np.asarray(x), np.asarray(y)
  18. return sgn*x**2, y
  19. extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
  20. lon_cycle=None,
  21. lat_cycle=None,
  22. # (0, np.inf),
  23. lon_minmax=None,
  24. lat_minmax=None,
  25. )
  26. grid_helper = GridHelperCurveLinear((tr, inv_tr),
  27. extreme_finder=extreme_finder)
  28. ax1 = Subplot(fig, 111, grid_helper=grid_helper)
  29. # ax1 will have a ticks and gridlines defined by the given
  30. # transform (+ transData of the Axes). Note that the transform of
  31. # the Axes itself (i.e., transData) is not affected by the given
  32. # transform.
  33. fig.add_subplot(ax1)
  34. ax1.imshow(np.arange(25).reshape(5, 5),
  35. vmax=50, cmap=plt.cm.gray_r,
  36. interpolation="nearest",
  37. origin="lower")
  38. # tick density
  39. grid_helper.grid_finder.grid_locator1._nbins = 6
  40. grid_helper.grid_finder.grid_locator2._nbins = 6
  41. if 1:
  42. fig = plt.figure(1, figsize=(7, 4))
  43. fig.clf()
  44. curvelinear_test1(fig)
  45. plt.show()

下载这个示例