【问题标题】:Seaborn despine with two y-scales (twinx)Seaborn depine 有两个 y 尺度 (twinx)
【发布时间】:2016-09-24 11:48:41
【问题描述】:

如何防止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 轴或将右轴放在左边。

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

【问题讨论】:

  • 不确定我是否理解正确,因为如果我运行你的 sn-p,我会在一侧得到一个 y 刻度,在另一侧得到一个 y 刻度。这不是你想要的吗?
  • 也许你可以加个图..
  • 公平点 - 我没有在我的问题中设置 seaborn 风格,这使得绝望变得不必要!

标签: python matplotlib seaborn


【解决方案1】:

我想这就是你想要的。

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')

【讨论】:

  • 如果你想在两边显示轴线(这是我想做的),那么你这样做:``` sns.despine(ax=ax, right=True , left=False) sns.despine(ax=ax2, left=True, right=False) ```
猜你喜欢
  • 2021-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-23
  • 2022-01-14
  • 2018-12-10
  • 2022-10-07
相关资源
最近更新 更多