Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

plot a scatter graph for a dictionary

Please I need help I want to plot a graph using

pandas.dataframe.plot(kind='scatter' , x=x , y=y )

for a dictionary type {‘2022-01-30’: 50, ‘2022-01-31’: 152, ‘2022-02-01’: 41 }

Please how can I use dictionary since i need a title

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It is giving me the error x is not defined
x is the key and
y is the value

but on the graph x should be ‘Date’ and y should be ‘Quantity’

>Solution :

You have to create a DataFrame first:

import pandas as pd
import matplotlib.pyplot as plt

data = {'2022-01-30': 50, '2022-01-31': 152, '2022-02-01': 41}
df = pd.Series(data, name='y').rename_axis('x').reset_index()
df.plot(kind='scatter', x='x', y='y')
plt.show()

Output:
enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading