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

Scatterplot error : "x and y must be the same size" but they have the same size

I would like to make a scatterplot with the dataframe :"df_death_mois1". But it doesn’t work. The error message is : "x and y must be the same size". Can you help me ?

import pandas as pd 
import matplotlib.pyplot as plt
members = pd.read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/members.csv")
expeditions = pd.read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-09-22/expeditions.csv")
expeditions['highpoint_date'] = pd.to_datetime(expeditions['highpoint_date'])
lesmois = expeditions['highpoint_date'].dt.month
expeditions["mois"] = lesmois
expeditions
 df_members_mois = pd.merge(members,expeditions[['expedition_id','mois']], on='expedition_id', how='inner')
 df_death_mois = df_members_mois[df_members_mois["death_cause"]=="Avalanche"]
 df_death_mois
 df_death_mois1 = df_death_mois.groupby("mois")['death_cause'].count()
 df_death_mois1 = df_death_mois1.to_frame()
 df_death_mois1
 plt.scatter(x="mois", y = "death_cause", data = df_death_mois1)
 plt.title('scatterplot')
 plt.xlabel('x')
 plt.ylabel('y')
 plt.show()

>Solution :

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

reset_index and then call plot.scatter:

>>> df_death_mois1.reset_index().plot.scatter(x="mois", y="death_cause")

enter image description here

With matplotlib.pyplot you can use:

>>> plt.scatter(x=df_death_mois1.index, y=df_death_mois1["death_cause"])
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