Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
Pandas 如何在seaborn的Swarmlot中设置x坐标?_Pandas_Seaborn_Swarmplot - Fatal编程技术网

Pandas 如何在seaborn的Swarmlot中设置x坐标?

Pandas 如何在seaborn的Swarmlot中设置x坐标?,pandas,seaborn,swarmplot,Pandas,Seaborn,Swarmplot,尝试在seaborn中使用3种不同的向量进行Swarmlot。我想让每个向量在不同的x坐标和不同的颜色 不幸的是,所有的教程都有一些格式的数据,我真的找不到关于。。。到目前为止,我得到的是: #!/usr/bin/env python3 import numpy as np import matplotlib.pyplot as plt import seaborn import pandas as pd # Create figure fig = plt.figure() ax = fig.

尝试在seaborn中使用3种不同的向量进行Swarmlot。我想让每个向量在不同的x坐标和不同的颜色

不幸的是,所有的教程都有一些格式的数据,我真的找不到关于。。。到目前为止,我得到的是:

#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import seaborn
import pandas as pd

# Create figure
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_ylabel('Evaluations')

colors = [
    'tab:orange',
    'tab:green',
    'tab:red',
]

labels = [
    'Method 2',
    'Method 3',
    'Method 4',
]

data = [
    [1, 2.1, 3.2, 4.5, 3.6, 2.7, 1.4],
    [2.2, 4.7, 5.1, 4.4, 3.8, 5, 3.4],
    [8.4, 7.2, 6.1, 5.4, 8.1, 7.4, 6.8],
]
data = np.array(data).T

df = pd.DataFrame(data, columns=labels)

seaborn.swarmplot(data=df, y='Method 2', color=colors[0])
seaborn.swarmplot(data=df, y='Method 3', color=colors[1])
seaborn.swarmplot(data=df, y='Method 4', color=colors[2])

plt.show()
这几乎可以工作,但在同一轴上绘制所有内容:

此外,标签应位于x轴而不是y轴上。我很确定我错过了一些基本的东西。有人吗?

试试:

df2 = df.melt()

colors = ["orange", "green", "red"]
sns.swarmplot(data=df2, x = 'variable', y='value', palette =colors)
plt.show()

谢谢,这使他们在不同的轴,但仍然没有给他们我需要的颜色