Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何覆盖两个海生地块? 我有两个数据集,考虑下面的MWE,从中我想用不同的样式参数创建RelType。 from io import StringIO import numpy as np import pandas as pd import seaborn as sns data1 = """index x y group ground_x_A ground_y_A ground_x_B ground_y_B 0 27 26 A 20 15 40 45 1 26 27 A 20 15 40 45 2 28 22 A 20 15 40 45 3 25 24 A 20 15 40 45 4 29 31 A 20 15 40 45 5 46 29 B 20 15 40 45 6 39 37 B 20 15 40 45 7 38 41 B 20 15 40 45 8 44 46 B 20 15 40 45 9 46 38 B 20 15 40 45 10 37 33 B 20 15 40 45""" df = pd.read_csv(StringIO(data1), index_col=[0], sep=" ", skipinitialspace=True) sns.set_style("whitegrid") sns.relplot(data = df, x = 'x', y = 'y', hue = 'group', s = 25) sns.relplot(data = df, x = 'ground_x_A', y = 'ground_y_B', s = 100) sns.relplot(data = df, x = 'ground_x_B', y = 'ground_y_B', s = 100)_Python_Plot_Seaborn - Fatal编程技术网

Python 如何覆盖两个海生地块? 我有两个数据集,考虑下面的MWE,从中我想用不同的样式参数创建RelType。 from io import StringIO import numpy as np import pandas as pd import seaborn as sns data1 = """index x y group ground_x_A ground_y_A ground_x_B ground_y_B 0 27 26 A 20 15 40 45 1 26 27 A 20 15 40 45 2 28 22 A 20 15 40 45 3 25 24 A 20 15 40 45 4 29 31 A 20 15 40 45 5 46 29 B 20 15 40 45 6 39 37 B 20 15 40 45 7 38 41 B 20 15 40 45 8 44 46 B 20 15 40 45 9 46 38 B 20 15 40 45 10 37 33 B 20 15 40 45""" df = pd.read_csv(StringIO(data1), index_col=[0], sep=" ", skipinitialspace=True) sns.set_style("whitegrid") sns.relplot(data = df, x = 'x', y = 'y', hue = 'group', s = 25) sns.relplot(data = df, x = 'ground_x_A', y = 'ground_y_B', s = 100) sns.relplot(data = df, x = 'ground_x_B', y = 'ground_y_B', s = 100)

Python 如何覆盖两个海生地块? 我有两个数据集,考虑下面的MWE,从中我想用不同的样式参数创建RelType。 from io import StringIO import numpy as np import pandas as pd import seaborn as sns data1 = """index x y group ground_x_A ground_y_A ground_x_B ground_y_B 0 27 26 A 20 15 40 45 1 26 27 A 20 15 40 45 2 28 22 A 20 15 40 45 3 25 24 A 20 15 40 45 4 29 31 A 20 15 40 45 5 46 29 B 20 15 40 45 6 39 37 B 20 15 40 45 7 38 41 B 20 15 40 45 8 44 46 B 20 15 40 45 9 46 38 B 20 15 40 45 10 37 33 B 20 15 40 45""" df = pd.read_csv(StringIO(data1), index_col=[0], sep=" ", skipinitialspace=True) sns.set_style("whitegrid") sns.relplot(data = df, x = 'x', y = 'y', hue = 'group', s = 25) sns.relplot(data = df, x = 'ground_x_A', y = 'ground_y_B', s = 100) sns.relplot(data = df, x = 'ground_x_B', y = 'ground_y_B', s = 100),python,plot,seaborn,Python,Plot,Seaborn,我想覆盖生成的图,即将它们组合成一个图,图2和图3中的点与图1中每组的颜色匹配。有人能给我指出正确的方向吗 我尝试调整示例中介绍的解决方案失败。relplot会在每次调用时创建一个新的图形FaceGrid,因此您无法使用它。也就是说,relplot使用scatterplot进行实际绘图 palette={'A':'C3', 'B':'C4'} sns.scatterplot(data = df, x = 'x', y = 'y', hue = 'group', s = 25, palette=

我想覆盖生成的图,即将它们组合成一个图,图2和图3中的点与图1中每组的颜色匹配。有人能给我指出正确的方向吗

我尝试调整示例中介绍的解决方案失败。

relplot会在每次调用时创建一个新的图形FaceGrid,因此您无法使用它。也就是说,relplot使用scatterplot进行实际绘图

palette={'A':'C3', 'B':'C4'}

sns.scatterplot(data = df, x = 'x', y = 'y', hue = 'group', s = 25, palette=palette)
sns.scatterplot(data = df, x = 'ground_x_A', y = 'ground_y_B', s = 100, color=palette['A'])
sns.scatterplot(data = df, x = 'ground_x_B', y = 'ground_y_B', s = 100, color=palette['B'])
relplot会在每次调用时创建一个新的图形FaceGrid,因此您不能使用它。也就是说,relplot使用scatterplot进行实际绘图

palette={'A':'C3', 'B':'C4'}

sns.scatterplot(data = df, x = 'x', y = 'y', hue = 'group', s = 25, palette=palette)
sns.scatterplot(data = df, x = 'ground_x_A', y = 'ground_y_B', s = 100, color=palette['A'])
sns.scatterplot(data = df, x = 'ground_x_B', y = 'ground_y_B', s = 100, color=palette['B'])

考虑使用concat将数据重组为长格式,以获得一个relplot,其中包含两行用于色调因子分解的新组值

main_df = df.loc[:, ['x', 'y', 'group']]

ground_A_df = (df.loc[:, ['ground_x_A', 'ground_y_A']]
                 .assign(group = 'ground_A')
                 .set_axis(['x', 'y', 'group'], axis='columns')
                 .drop_duplicates())
                
ground_B_df = (df.loc[:, ['ground_x_B', 'ground_y_B']]
                 .assign(group = 'ground_B')
                 .set_axis(['x', 'y', 'group'], axis='columns')
                 .drop_duplicates())
                
# BUILD LONG FORM DATASET           
long_df = pd.concat([main_df, ground_A_df, ground_B_df], ignore_index=True)


sns.set_style("whitegrid")
sns.relplot(data = long_df, x = 'x', y = 'y', hue = 'group', s = 25)

可选地,考虑将COL参数积分,并将接地点作为比其他数据点大的圆:

main_df=df.loc[:,['x','y','group']] .assignground=lambda x:x[“组”],大小=25 具有列表理解的DRY-er代码 地面dfs=[df.loc[:,[f'ground_x{i}',f'ground_y{i}'] .assigngroup=i,ground=i,size=100 .设置_轴['x','y','group','ground','size'],轴='columns' .删除重复项 对于列表'AB'中的i] 使用地面和大小的新列构建长格式数据集 long_df=pd.concat[main_df]+ground_dfs,ignore_index=True sns.set_stylewhitegrid sns.relplotdata=long_df,x='x',y='y',col='ground', 色调='group',大小='size',图例='full'
考虑使用concat将数据重组为长格式,以获得一个relplot,其中包含两行用于色调因子分解的新组值

main_df = df.loc[:, ['x', 'y', 'group']]

ground_A_df = (df.loc[:, ['ground_x_A', 'ground_y_A']]
                 .assign(group = 'ground_A')
                 .set_axis(['x', 'y', 'group'], axis='columns')
                 .drop_duplicates())
                
ground_B_df = (df.loc[:, ['ground_x_B', 'ground_y_B']]
                 .assign(group = 'ground_B')
                 .set_axis(['x', 'y', 'group'], axis='columns')
                 .drop_duplicates())
                
# BUILD LONG FORM DATASET           
long_df = pd.concat([main_df, ground_A_df, ground_B_df], ignore_index=True)


sns.set_style("whitegrid")
sns.relplot(data = long_df, x = 'x', y = 'y', hue = 'group', s = 25)

可选地,考虑将COL参数积分,并将接地点作为比其他数据点大的圆:

main_df=df.loc[:,['x','y','group']] .assignground=lambda x:x[“组”],大小=25 具有列表理解的DRY-er代码 地面dfs=[df.loc[:,[f'ground_x{i}',f'ground_y{i}'] .assigngroup=i,ground=i,size=100 .设置_轴['x','y','group','ground','size'],轴='columns' .删除重复项 对于列表'AB'中的i] 使用地面和大小的新列构建长格式数据集 long_df=pd.concat[main_df]+ground_dfs,ignore_index=True sns.set_stylewhitegrid sns.relplotdata=long_df,x='x',y='y',col='ground', 色调='group',大小='size',图例='full'
对于第二个重新绘制,您的意思是将x_A与y_A进行比较,并将后者误键入y_B?对于第二个重新绘制,您的意思是将x_A与y_A进行比较,并将后者误键入y_B?