如何将网格线(垂直和水平)添加到seaborn猫图?我发现可以在箱线图上做到这一点,但我有多个方面,因此需要一个猫图。与其他答案相反,catplot 不允许争论ax。
这段代码是从这里借用的。
import seaborn as sns
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
plt.show()
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢你!
编辑:提供的答案有效,但对于多面图,只有最后一个图继承网格。
import seaborn as sns
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise)
plt.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么以及如何解决它吗?
我无法在 Seaborn/Matplotlib 中旋转我的 xlabel。我尝试了很多不同的解决方案,但无法修复它。我在 stackoverflow 上看到了很多相关问题,但它们对我不起作用。
我当前的绘图如下所示,但我希望 xlabel 旋转 90 度。
@staticmethod
def plotPrestasjon(plot):
sns.set(style="darkgrid")
ax = sns.catplot(x="COURSE", y="FINISH", hue="COURSE",
col="BIB#", data=plot, s=9, palette="Set2")
ax.set(xlabel='COURSES', ylabel='FINISH (sec)')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我努力了:
ax.set_xticklabels(ax.get_xticklabels(), rotation=90)
Run Code Online (Sandbox Code Playgroud)
但这无法生成情节。我有什么想法可以解决它吗?
有几个不同的model_names。我正在尝试使用以下代码在 seaborn catplot 中绘制数据:
sns.set(style="whitegrid")
sns.catplot(x='model_name', y='score', hue='train_val_test', col='score_name',
data=classification_scores, kind='bar', height=4, aspect=.8)
Run Code Online (Sandbox Code Playgroud)
如何更改格式以使图形显示在 2x2 网格上?将它们全部放在一条线上太局促了。
我使用 catplot 函数创建了一个关于死亡/受伤人数的猫图。然而,由于两者的比例非常不同,第二张图中的条形非常小并且无法读取。无论如何,我可以重新缩放第二个图表的 y 轴吗?并向两个图表添加数据标签?
grid = sns.catplot(x = 'borough',
y = 'Injured/Killed',
hue = 'Commuter Type',
col = 'Injury Type',
data = tabular_breakdown,
kind = 'bar')
Run Code Online (Sandbox Code Playgroud)

catplot 函数有一个名为 kind 的选项。它允许我指定“条”、“点”等。我正在寻找线图。我使用 catplot 并排显示两个类别,使用相同的时间刻度,绘制两种不同产品的销售额。目标是并排展示这两种趋势。
我需要的是这样的(带有中线):
我尝试过的是这段代码:
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise, kind="box")
bars = g.axes[0][0].patches
hatches=['//','..','xx','//','..','xx','//','..','xx']
for pat,bar in zip(hatches,bars):
bar.set_hatch(pat)
Run Code Online (Sandbox Code Playgroud)
这只会生成第一个数字。第3-6行的想法来自这个问题。但进入第 3 行的想法axes[0][0]来自于这个问题。
因为 FacetGrid 没有补丁或容器等属性,所以很难将单个图中的影线答案适应分类图,所以我无法弄清楚。
我有两个疑问:
plt.figure(figsize=(40,20))
g = sns.catplot(x = 'Subject', y = 'EE Score',data = df , hue = 'Session',col='Grade',sharey = True,sharex = True,
hue_order=["2017-18", "2018-19", "2019-20"], kind="bar");
#plt.legend(bbox_to_anchor=(1, 1), loc=2)
g.set(ylim=(0, 100))
g.set_axis_labels("Subject", "EE Score")
ax = g.facet_axis(0,0)
for p in ax.patches:
ax.text(p.get_x() + 0.015,
p.get_height() * 1.02,
'{0:.1f}'.format(p.get_height()),
color='black', rotation='horizontal', size=12)
ax = g.facet_axis(0,1)
for p in ax.patches:
ax.text(p.get_x() + 0.015,
p.get_height() * 1.02,
'{0:.1f}'.format(p.get_height()),
color='black', rotation='horizontal', size=12)
ax = g.facet_axis(0,2)
for p in ax.patches:
ax.text(p.get_x() + …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成不同的箱线图,描述某些产品系列和行业组(“生产”、“贸易”、“商业”、“休闲与福祉”)的变量分布。
我想知道:
在我正在使用的代码下方,这里有一张图像向您展示我得到的内容 --> Catplot Image。
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context("talk")
boxplot = sns.catplot(
x='family',
y='lag',
hue="SF_type",
col="industry_group",
data=df1,
kind="box",
orient="v",
height=8,
aspect=2,
col_wrap=1,
order=fam_sort,
palette='Set3',
notch=True,
legend=True,
legend_out=True,
showfliers=False,
showmeans=True,
meanprops={
"marker":"o",
"markerfacecolor":"white",
"markeredgecolor":"black",
"markersize":"10"
}
)
boxplot.fig.suptitle("Boxplots by Product Basket, Industry Group & SF Type", y=1.14)
#repeat xticks for each plot
for ax in boxplot.axes:
plt.setp(ax.get_xticklabels(), visible=True, rotation=75)
plt.subplots_adjust(hspace=1.2, top = 1.1)
#remove axis titles
for ax in boxplot.axes.flatten(): …Run Code Online (Sandbox Code Playgroud)