我正在尝试绘制一系列很长的箱线图。我喜欢里面绘制的微型箱线图的美感 violinplot (通过seaborn.violinplot 的“inner”参数控制)。有谁知道有一种简单的方法可以只绘制这个迷你箱线图而无需绘制 fiddle 图的其余部分?谢谢!
最佳答案
fiddle 是PolyCollection
对象。您可以从轴中删除所有PolyCollection
。如果轴仅包含 fiddle 图而不包含任何其他 PolyCollection
,则这是有意义的。
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x="day", y="total_bill", data=tips)
from matplotlib.collections import PolyCollection
for a in ax.findobj(PolyCollection):
a.remove()
ax.relim()
ax.autoscale_view()
plt.show()
或者更简单,
for a in ax.collections:
a.remove()
关于matplotlib - 有什么方法可以从seaborn fiddle 图中得到迷你箱线图吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52971882/