gpt4 book ai didi

python - 带有两个 y 尺度的 Seaborn despine (twinx)

转载 作者:行者123 更新时间:2023-11-28 21:09:52 24 4
gpt4 key购买 nike

如何防止 seaborn.despine 将我的两个 y 尺度都放在绘图的左侧?到目前为止我想到的最好的是:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set_style("white")

fig, ax = plt.subplots()
ax.plot(np.random.rand(10))
ax2 =ax.twinx()
ax2.plot(100*np.random.rand(10))
sns.despine(ax=ax, right=True, left=True)
sns.despine(ax=ax2, left=True, right=False)

但任何其他组合都不会取消 y 轴或将右轴放在左侧。

上面的输出:(期望的输出没有刺,只有左右数字)

enter image description here

最佳答案

我猜这就是你想要的。

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set_style("white")

fig, ax = plt.subplots()
ax.plot(np.random.rand(10))
ax2 =ax.twinx()
ax2.plot(100*np.random.rand(10))
sns.despine(ax=ax, right=True, left=True)
sns.despine(ax=ax2, left=True, right=False)
ax2.spines['right'].set_color('white')

no spines, just numbers on left and right

关于python - 带有两个 y 尺度的 Seaborn despine (twinx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37461434/

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