我目前有一个seaborn relplot
harker = sns.relplot(data = majorsLong, x = "SiO2", y = "Wt %", palette = colors,
markers = marks, style = "Lithology", hue = "Lithology",
kind = "scatter", col = "Oxide", col_wrap = 2, s = 150,
facet_kws = {'sharey': False, 'sharex': True},
linestyle = "None", legend = False)
Run Code Online (Sandbox Code Playgroud)
这就创造了这个数字。
我想用这个数字做两件事。首先,我想删除所有子图标题。其次,我想将每个 y 标签(甚至内部标签)设置为"Oxide" + " Wt %",但也不知道该怎么做。
有没有办法创建一个 Seaborn 线图,所有线均为灰色,平均值为红线?我正在尝试执行此操作,relplot但我不知道如何将平均值与数据分开(并且似乎未绘制平均值?)。
制作可重复的数据框
np.random.seed(1)
n1 = 100
n2 = 10
idx = np.arange(0,n1*2)
x, y, cat, id2 = [], [], [], []
x1 = list(np.random.uniform(-10,10,n2))
for i in idx:
x.extend(x1)
y.extend(list(np.random.normal(loc=0, scale=0.5, size=n2)))
cat.extend(['A', 'B'][i > n1])
id2.append(idx[i])
id2 = id2 * n2
id2.sort()
df1 = pd.DataFrame(list(zip(id2, x, y, cat)),
columns =['id2', 'x', 'y', 'cat']
)
Run Code Online (Sandbox Code Playgroud)
绘图尝试
g = sns.relplot(
data=df1, x='x', y='y', hue='id2',
col='cat', kind='line',
palette='Greys',
facet_kws=dict(sharey=False,
sharex=False
),
legend=False
)
Run Code Online (Sandbox Code Playgroud)
如果我需要进行特定的更改或面向细节的可视化,我已经学会了不要使用seaborn,但我觉得我有时没有充分利用它所提供的功能。
我想专门用seaborn 指定调色板。我不确定我是否遗漏了一些东西,或者这是使用facetgrid时无法解决的细节?
df = pd.DataFrame()
df['I'] = np.full(20,1)
df['J'] = np.arange(0,20,1)
df['K'] = [1]*12 + [2]*8
df['CM_Hard'] = [1]*10 + [2] + [0] + [2]*8
df['Realization'] = ['p25']*10 + ['p50']*9 + ['p75']
for layer in df['K'].unique():
layer_data_slice = df.groupby('K').get_group(layer)
g = sns.FacetGrid(layer_data_slice, col="Realization",hue="CM_Hard")
g.map_dataframe(sns.scatterplot, x="I", y="J", s=50, marker='+', palette='deep')
g.add_legend()
g.fig.suptitle("Training Realizations, Layer: {}".format(int(layer)), size=16, y=1.05)
figure_title = 'Training_Layer_{}'.format(int(layer))
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下内容进行调色板定义,但它不会影响绘图:
palette = {0:"tab:cyan", 1:"tab:orange", 2:"tab:purple"}
Run Code Online (Sandbox Code Playgroud)
已尝试使用“tab:color”、“color”和 RGB 参考,但没有成功。没有错误,它只是在更改时不执行任何操作。
我有一个relplot列拆分为一个变量的列。我想添加一个没有 subplot 或 subpanel 的附加列。为了给出一个清晰的例子,假设我有以下情节:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
x = np.random.random(10000)
t = np.random.randint(low=0, high=3, size=10000)
y = np.multiply(x, t)
df = pd.DataFrame({'x': x, 't': t, 'y': y})
g = sns.relplot(df, x='x', y='y', col='t')
Run Code Online (Sandbox Code Playgroud)
这会生成类似的情节
我想要第四列t=3不显示数据也不显示轴。我只想要一个与前三个子图大小相同的空白白色子图。我怎样才能做到这一点?
Dataframe
df
Sample Type y1 y2 y3 y4
S1 H 1000 135 220 171
S2 H 2900 1560 890 194
S3 P 678 350 127 255
S4 P 179 510 154 275
Run Code Online (Sandbox Code Playgroud)
I want to plot y1, y2, y3, y4 vs Sample scatterplot with hue as Type.
Is there any way to do it in Seaborn?
python ×5
relplot ×5
seaborn ×5
facet-grid ×3
matplotlib ×2
palette ×1
pandas ×1
scatter-plot ×1