pandas 熊猫散点图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13929884/
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-13 20:32:54  来源:igfitidea点击:

Pandas scatter plot

pythonpandas

提问by user1911866

Im new to Python and Pandas but have a CSV file with multiple columns that I have read in to a dataframe. I would like to plot a scatter plot of x=Index and y='data'. Where the index is Index of the dataframe and is a date. Thanks heaps Jason

我是 Python 和 Pandas 的新手,但有一个包含多列的 CSV 文件,我已将其读入数据帧。我想绘制 x=Index 和 y='data' 的散点图。其中索引是数据框的索引并且是日期。谢谢堆杰森

采纳答案by Andy Hayden

You can use plot_date:

您可以使用plot_date

plot_date(df.index, df.data)

回答by Little Bobby Tables

Whilst, I guess technically not a scatter plot, you can use the pandas.plotfunction with point markers drawn on and no lines.

虽然,我想从技术上讲不是散点图,但您可以使用pandas.plot带有绘制点标记且没有线条的函数。

df.plot(marker='o', linewidth=0)

enter image description here

在此处输入图片说明

This then allows us to use all of the convenient pandas functionality you desire. e.g. plot two series and different scales, using a single function,

这样我们就可以使用您想要的所有方便的 Pandas 功能。例如,使用单个函数绘制两个系列和不同的比例,

df.plot(marker='o', linewidth=0, secondary_y='y2')

enter image description here

在此处输入图片说明

The downside to this is that you lose some of the scatter functionality such as shading and sizing the markers differently.

这样做的缺点是您会失去一些分散功能,例如以不同方式对标记进行着色和调整大小。

Still, if your aim is a quick scatter plot, this might be the easiest route.

不过,如果您的目标是快速散点图,这可能是最简单的路线。