在下面的代码中,当使用swarmplot函数绘制蜂群图时,我观察到数据点在数据集2中没有分散。但如果我将数据集更改为数据集1,数据点会分散得很好。我需要的是,即使有了数据集2,点也应该分散得很好。我甚至试过改变散布的大小,但没有结果。有人能帮我解决这个问题吗??
import matplotlib.pyplot as plt
import numpy as np
import seaborn
# Making beeswarm plot
A=np.array([0.02,0.02,0.02,0.04,0.04,0.05,0.05,0.05,0.05,0.05,0.09,0.09,0.09,0.09,0.09,0.1,0.1,0.1,0.1,0.8,0.8,0.8,0.8]) # data set 1
#A=np.array([20,20,20,20,50,50,50,35,35,35,45,45,58,58,58,58,69,69,69,63,63,63,36,63,77,78,80,80,80,80]) # data set 2
data = A
x_labels = " Depth (Microns)"
y_labels = " Diameter (Microns)"
seaborn.set(color_codes=True)
fig = plt.figure(figsize=(16, 16))
axes = fig.add_subplot(1, 1, 1, aspect=1)
# add title to plot
plt.title("Beeswarm Distribution Plots of Swept Droplet Diameters")
# plot data on swarmplot
seaborn.swarmplot(data=data, color="blue", size=8)
# y-axis label
axes.set(ylabel=y_labels)
axes.set(xlabel=x_labels)
axes.set_xticklabels(['200'])
plt.show()我附上了使用数据集1和数据集2 enter image description here生成的蜂群图的图像
发布于 2021-06-06 22:51:10
去掉axes的aspect=1标志,这样代码行就会显示为
axes = fig.add_subplot(1, 1, 1)或者,您可以完全避免子图行话,除非您打算在此图中添加更多子图。
import matplotlib.pyplot as plt
import numpy as np
import seaborn
# Making beeswarm plot
# A=np.array([0.02,0.02,0.02,0.04,0.04,0.05,0.05,0.05,0.05,0.05,0.09,0.09,0.09,0.09,0.09,0.1,0.1,0.1,0.1,0.8,0.8,0.8,0.8]) # data set 1
A=np.array([20,20,20,20,50,50,50,35,35,35,45,45,58,58,58,58,69,69,69,63,63,63,36,63,77,78,80,80,80,80]) # data set 2
data = A
x_labels = " Depth (Microns)"
y_labels = " Diameter (Microns)"
seaborn.set(color_codes=True)
fig = plt.figure(figsize=(16, 16))
# add title to plot
plt.title("Beeswarm Distribution Plots of Swept Droplet Diameters")
# plot data on swarmplot
seaborn.swarmplot(data=data, color="blue", size=8)
# y-axis label
plt.ylabel(y_labels)
plt.xlabel(x_labels)
plt.xticks(labels=['200'], ticks=[0])
plt.show()https://stackoverflow.com/questions/67859189
复制相似问题