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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-11-09 11:00:00 +0000
Seen: 8 times
Last updated: May 02 '21
The mplfinance plot displays accurately, but the datetime format is unusual.
How can the black color be modified in Seaborn boxplots?
How can I modify the arrow axes and their tick labels in a Matplotlib plot?
What is the procedure for incorporating superscript in a forest.meta plot?
How to create a plot using mplfinance and PyQt5 that includes a volume graph?
What is the process for creating a set of vertical lines using gnuplot?
In sagemath, what is the procedure for plotting vector functions?
How can the clipping of objects in matplotlib 3D be modified?
What is the process for creating a box plot in Matplotlib that includes two summary statistics?