Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know how many data points Matplotlib is using for a scatterplot

I am new here. I was wandering if there is a simple code to print the number of data points used on a Matplotlib scatterplot and perhaps print it on the plot as "N=...".

Thank you very much

like image 496
GiuliaS Avatar asked Sep 16 '25 01:09

GiuliaS


1 Answers

If you need to get back to the data later, and you don't have access to x and y anymore for some reason, you can retrieve them like so:

import numpy as np
import matplotlib.pyplot as plt 

x = ...
y = ...
artist = plt.scatter(x, y)

# ...
# Things that cause you to lose x and y.
# ...

xy = artist.get_offsets()
x, y = np.array(xy).transpose()
print(len(x))
like image 141
Guimoute Avatar answered Sep 19 '25 02:09

Guimoute