1
我想知道如果有一個更優雅的方式(通過消除任何for循環,或通過其他方式來繪製網格),達到這個數字:Matplotlib:雙軸和set_equal
nx, ny = 8, 6
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlabel('Pixel X-coordinate')
ax.set_ylabel('Pixel Y-coordinate')
for i in range(nx-1):
ax.axvline(i+0.5, color='k')
for i in range(ny-1):
ax.axhline(i+0.5, color='k')
ax_twiny = ax.twiny()
ax_twiny.set_xticks(np.arange(nx-1) + 0.5)
ax_twiny.set_xticklabels(np.linspace(-600, 600, nx-1))
ax_twiny.set_xlabel(u'World X-coordinate [µm]')
ax_twinx = ax.twinx()
ax_twinx.set_yticks(np.arange(ny-1) + 0.5)
ax_twinx.set_yticklabels(np.linspace(-400, 400, ny-1))
ax_twinx.set_ylabel(u'World Y-coordinate [µm]')
for a in (ax, ax_twiny, ax_twinx):
a.set_xlim(-0.5, nx - 0.5)
a.set_ylim(-0.5, ny - 0.5)
a.set_aspect('equal')
我試圖設置次刻度繪製使用ax.[xy]axis.grid(True, which='minor')
網格,但是當我繪製雙軸(使用matplotlib
1.1
)網格消失。
http://sourceforge.net/mailarchive/forum.php?thread_name=012701ce5892%24683e5cb0%2438bb1610 %24%40earthlink.net&forum_name = matplotlib-devel < - 可能是有趣的 – tacaswell