python - 在 2D 变换后调整 Matplotlib 中的限制
问题描述
我想在从图像执行转换后更改绘图轴的值。没有任何转换,xy 限制只是图像的尺寸。首先,我应用 extent 来更改imshow的限制,但在那之后,我需要使用 matplotlib 进行第二次转换(一个表示缩放和平移的转换矩阵。
我按照以下教程中的步骤进行操作,但我得到的只是一个完全白色的图。如果我不在 imshow 中添加范围部分,我得到的是一个以像素为单位的 xy 坐标图(不需要),但数据绘制在正确的位置(x 轴接近 2e-3 和 4e- 4 为 y 轴)。
xmin, ymin, xmax, ymax = limits # limits are calculated before
fig, ax = plt.subplots(figsize=(12, 8))
ims = ax.imshow(data, clip_on = True, extent = [xmin, xmax, ymin, ymax], norm = LogNorm(), cmap = colourmap)
trans_data = transform + ax.transData
ims.set_transform(trans_data)
x1, x2, y1, y2 = ims.get_extent()
ax.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "y--", transform = trans_data)
ax.set_xlim(x1,x2)
ax.set_ylim(y1,y2)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
fig.colorbar(ims, ax = ax)
plt.tight_layout()
plt.savefig(plot_title + '.png')
plt.show()
解决方案
推荐阅读
- asp.net-core-mvc - 按下后退按钮时如何刷新页面?
- android - Android GridLayout 中只有灰色框
- python - 给定 Python 中的概率,从 LARGE 列表中选择项数
- aem - 将 sling 模型声明为 (adaptables = Resource.class) 有什么意义
- google-play-console - 为什么 google 允许某些公司拥有 2 个帐户 google play 开发人员?
- python - 为什么 LXML Write 不能很好地打印到新文件?
- javascript - 对组件做出反应的单元测试用例
- python-3.x - 如何在matplotlib的tight_layout下调整独立颜色条的大小(高度和宽度)
- spring - Spring Reactive Webclient 的请求级背压?
- c - Helgrind 在运行时停止程序