gpt4 book ai didi

python - 每行单独共享?

转载 作者:IT老高 更新时间:2023-10-28 20:37:31 27 4
gpt4 key购买 nike

我有一个动态创建的 2×2 绘图。在第一行中,我想在第二行 CDF 中绘制密度函数。我想要

  • 要分享的每一列 x
  • 要分享的每一行 y

也就是说,垂直对齐的两个对象具有相同的 x 轴,水平对齐的两个图具有相同的 y 轴。

但是,sharexsharey 强制它们对于所有子图都相同。如何解决这种轴共享问题?我知道我可以手动为每个轴分配一个共享伙伴,但这不适用于以下通用结构:

fig, axes = plt.subplots(nrows=2, ncols=2, sharex=True)
for i, lam in enumerate(lams):
axesNow = [axs[i] for axs in axes] # pick the ith column from axes
for i, Param.p in enumerate(pp):
axesNow[0].plot(somethingWithPDF)
axesNow[1].plot(somethingWithCDF)

for ax in axes.flatten(): ax.legend()

enter image description here

最佳答案

pyplot.subplots documentation描述了 sharexsharey kwargs 的 'col''row' 选项。特别是,我认为您希望:

fig, axes = plt.subplots(nrows=2, ncols=2, sharex='col', sharey='row')

关于python - 每行单独共享?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39472115/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com