我试图从使用matplotlib创建的绘图中完全删除y轴。我使用的代码是:
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.stats import skewnorm
f = plt.figure(figsize=(8,4))
ax = f.add_subplot(111)
colors = ["windows blue", "faded green", "dusty purple"]
colors = sns.xkcd_palette(colors)
b = 4
for j, a in enumerate([(0, 'No skew'), (b, 'Positive skew'), (-b, 'Negative skew')]):
x = np.linspace(skewnorm.ppf(0.001, a[0]), skewnorm.ppf(0.999, a[0]), 100)
y = skewnorm.pdf(x, a[0])
plt.plot(x, y, label=a[1], color=colors[j])
ax.yaxis.set_visible(False)
plt.legend(loc=2)
sns.despine()
这会产生一个删除了y轴刻度的图,但轴本身仍然可见(如下所示)。如何完全关闭此轴?
答案 0 :(得分:1)
您需要明确地将left
或bottom
参数提供给des sns.despine
。默认情况下,仅删除右轴和顶轴。
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.stats import skewnorm
f = plt.figure(figsize=(8,4))
ax = f.add_subplot(111)
colors = ["windows blue", "faded green", "dusty purple"]
colors = sns.xkcd_palette(colors)
b = 4
for j, a in enumerate([(0, 'No skew'), (b, 'Positive skew'), (-b, 'Negative skew')]):
x = np.linspace(skewnorm.ppf(0.001, a[0]), skewnorm.ppf(0.999, a[0]), 100)
y = skewnorm.pdf(x, a[0])
ax.plot(x, y, label=a[1], color=colors[j])
ax.yaxis.set_visible(False)
plt.legend(loc=2)
sns.despine(left=True)