简体   繁体   English

matplotlib.pyplot scatter plot 即使具有不同的值,也仅在图中显示单个点

[英]matplotlib.pyplot scatter plot only shows a single dot in the graph even with different values

I have a movie dataset, I want to scatter plot the mean of computed_sales column and mean of movie_facebook_likes.我有一个电影数据集,我想分散 plot 计算销售列的平均值和电影 Facebook 喜欢的平均值。 the mean value for computed_sales is 4097131.5023790644, while for movie_facebook_likes is 7524.472442505948. computed_sales 的平均值是 4097131.5023790644,而 movie_facebook_likes 的平均值是 7524.472442505948。 But the graph shows only a dot.但是该图只显示了一个点。

fig = plt.figure(figsize=(10,8))
plt.scatter(data["compute_sales"].mean(), data["movie_facebook_likes"].mean())
plt.show()

Mean is one value.平均值是一个值。 You have asked it to plot one value.你已经要求它给 plot 一个值。 This is expected behaviour这是预期的行为

Scatter plot takes a set of points. Scatter plot 取一组点。 All X-coordinates as one array and all Y-coordinates as one array.所有 X 坐标为一个数组,所有 Y 坐标为一个数组。 So you provided only one X-value and its corresponding Y-value.所以您只提供了一个 X 值及其对应的 Y 值。 So it is expected that you will only have one point in the plot which is (x,y) = (4097131.5023790644, 7524.472442505948) .因此,预计您在 plot 中只有一个点,即(x,y) = (4097131.5023790644, 7524.472442505948)

So .mean() only gives you one value which is why one point.所以.mean()只给你一个值,这就是为什么一分。 If you wanna plot them all, do this instead:如果您想要 plot 全部,请执行以下操作:

plt.scatter(data["compute_sales"], data["movie_facebook_likes"])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM