python - 如何在保持宽度相同的同时强制子图的纵横比?
问题描述
我正在尝试创建一个包含两个子图的图。1 列,2 行。与图像类似,但右侧没有子图
如何强制一个子图为正方形,而另一个子图具有相同的宽度而不是正方形?
我尝试了gridspec但没有成功:
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
fig = plt.figure(constrained_layout=True)
gs = GridSpec(nrows=4, ncols=3, height_ratios=[1, 1, 1, 1], figure=fig)
ax1 = fig.add_subplot(gs[:-1,:])
ax2 = fig.add_subplot(gs[-1,:])
我还尝试为两个子图设置纵横比,从而导致子图的宽度不同:
fig, axs = plt.subplots(2)
axs[0].set_aspect(1)
axs[1].set_aspect(2)
我也试过......但这会将子图的 x 范围固定为相同的值。
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
F = plt.figure()
grid = ImageGrid(F, 111,
nrows_ncols=(2, 1),
axes_pad=0.1,
)
grid[1].set_aspect(.4)
感谢您的任何建议...
解决方案
我可以按照 ImportanceOfBeingErnest 的建议提出一种可行的解决方案:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
fig = plt.figure(figsize=(10,12))
axScatter = plt.subplot(111)
axScatter.set_aspect(1.)
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("bottom", size=.8, pad=0.2)
谢谢!
推荐阅读
- node.js - 我可以检查我的机器人中的哪些文件给了我错误消息吗?
- python - 执行 python 弹性脚本时出现 503 TransportError
- java - 将新用户输入存储为 Discord 机器人(Java、IntelliJ)的参考
- c# - SQL 字符串大小减少
- jenkins-pipeline - 用于创建带有描述的文件夹的詹金斯管道示例
- java - 如何使用 Spring Boot 返回成功消息?
- algorithm - 寻找作为给定序列的子序列出现的最长弱孪生
- mysql - 如何在 MySQL 的 WHERE 和 ORDER BY 子句中查询索引?
- r - 为什么这个闪亮的应用程序中显示的闪亮反馈错误消息有时不会改变?
- facebook - 如何通过视频获取人口统计数据?