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

being told x and y are different sizes when plotting

i have the following code:

distrobution.plot(x = ["Observed", "Modelled"], y = ["Amount (mm)"], kind = "scatter", ylabel="Rainfall (mm)", figsize=(8,4), title ="Daily Rainfall Distrobution")

for the following dataframe:

df

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

but am getting the error:

‘x and y must be the same size’

How are they not the same size?

>Solution :

You have to plot each series separately:

fig, ax = plt.subplots(figsize=(8, 4))
df.plot.scatter(x='Observed', y="Amount (mm)", color='blue', ax=ax, legend=True)
df.plot.scatter(x='Modelled', y="Amount (mm)", color='green', ax=ax, legend=True)
ax.set_ylabel('Rainfall (mm)')
ax.set_xlabel('Count')
ax.set_title('Daily Rainfall Distribution')
ax.legend(['Observed', 'Modelled'], loc='upper right')
plt.show()

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