pandas 调整散点图中的点大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34049147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:18:35  来源:igfitidea点击:

Adjusting dot size in scatterplot

pythonpandasmatplotlibplotscatter-plot

提问by Baron Yugovich

I am doing

我在做

ax = df.plot(x=x_col, y=y_col, style=['o', 'rx'])

but I don't like that the data points are large circles. I have thousands of datapoints, so it makes the plot ugly. Any idea how I can make the dots smaller, i.e. have them be actual points, rather than circles? Or any alternative suggestions for this sort of scatterplot?

但我不喜欢数据点是大圆圈。我有数千个数据点,所以它使情节丑陋。知道如何使点变小,即让它们成为实际的点,而不是圆圈吗?或者对这种散点图有什么替代建议?

回答by Stefan

The DataFrame.plot()docsinclude the option to pass keyword arguments to the underlying matplotlibplotting method. As you can see here, there's an argument sfor the dot size. So you should be able to:

DataFrame.plot()文档包括对关键字参数传递到下面的选项matplotlib绘制方法。正如您在此处看到的,s对于点的大小存在争议。所以你应该能够:

ax = df.plot(kind='scatter', x=x_col, y=y_col, style=['o', 'rx'], s=12)

This is also illustrated in the pandasvisualization docs.

这也在pandas可视化文档中进行了说明。

回答by atomh33ls

The valid matplotlib marker stylesinclude; '.'(point) and ','(pixel).

有效matplotlib标记样式包括: '.'(点)和','(像素)。

So an alternative could be:

所以一个替代方案可能是:

ax = df.plot(x=x_col, y=y_col, style=['.', 'rx'])