1 | initial version |
To transform a histogram plot in a pandas dataframe into a scatter plot, you can follow these steps:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.DataFrame({'x':[1,3,3,4,5,7,7,8,9,10]})
plt.hist(data['x'], bins=5)
plt.show()
This will create a histogram plot:
counts, bins, _ = plt.hist(data['x'], bins=5)
freq = pd.DataFrame({'x': bins[:-1], 'y': counts})
plt.scatter(freq['x'], freq['y'])
plt.show()
This will create a scatter plot:
Note that the scatter plot does not contain any information about the binning of the histogram.