Pandas scatter plot

Pandas scatter plot



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




2 Answers
2



You can use plot_date:


plot_date


plot_date(df.index, df.data)





Great. I'd didnt realise it was as simple as passing df.index. I was having trouble because I was trying to use the column names but the index doesnt have a column name.
– user1911866
Dec 18 '12 at 11:39





I would use `df.plot()', would be more "pandas-like".
– bmu
Dec 18 '12 at 20:03





@bmu trying to scatter plot with datetimes is not as straightforward as you might expect. You will end up with KeyErrors if you attempt to provide datetimes as the x in df.plot() and you'll notice pd.Series.plot() has no 'scatter' argument for kind.
– conner.xyz
Sep 21 '15 at 20:52



df.plot()


pd.Series.plot()


kind



Whilst, I guess technically not a scatter plot, you can use the pandas.plot function 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,


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.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế