Here you have a working example:
import random
import numpy
from matplotlib import pyplot
x = [random.gauss(3,1) for _ in range(400)]
y = [random.gauss(4,2) for _ in range(400)]
bins = numpy.linspace(-10, 10, 100)
pyplot.hist(x, bins, alpha=0.5, label="x")
pyplot.hist(y, bins, alpha=0.5, label="y")
pyplot.legend(loc="upper right")
pyplot.show()
Related Contents:
- Plot two histograms on single chart with matplotlib
- Bin size in Matplotlib (Histogram)
- Histogram Matplotlib
- How to have logarithmic bins in a Python histogram
- Plot a histogram such that bar heights sum to 1 (probability)
- Python histogram outline
- Matplotlib – label each bin
- Matplotlib/Pandas error using histogram
- How to use log scale with pandas plots
- Plot a histogram from a Dictionary
- Logarithmic y-axis bins in python
- How to add vertical lines to a distribution plot
- changing default x range in histogram matplotlib
- Plotting a histogram from pre-counted data in Matplotlib
- Multiple histograms in Pandas
- Plot histogram with colors taken from colormap
- Plotting transparent histogram with non transparent edge
- Circular / polar histogram in python
- How to add edge color to a histogram
- Histogram in matplotlib, time on x-Axis
- Changing the tick frequency on the x or y axis
- Scatter plot with different text at each data point
- “UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.” when plotting figure with pyplot on Pycharm
- Plot smooth line with PyPlot
- How can I plot a confusion matrix? [duplicate]
- How to plot different groups of data from a dataframe into a single figure
- Invert image displayed by imshow in matplotlib
- matplotlib y-axis label on right side
- How do you plot a vertical line on a time series plot in Pandas?
- How to show two figures using matplotlib?
- How to change legend fontsize with matplotlib.pyplot
- Matplotlib scatter plot legend
- What does .shape[] do in “for i in range(Y.shape[0])”?
- How to prevent numbers being changed to exponential form in a plot
- Using Colormaps to set color of line in matplotlib
- Matplotlib xticks not lining up with histogram
- add title to collection of pandas hist plots
- Matplotlib: Plotting numerous disconnected line segments with different colors
- Plotting pandas timedelta
- How to show matplotlib plots?
- How to add trendline to a scatter plot
- Keep plotting window open in Matplotlib
- Is “from matplotlib import pyplot as plt” == “import matplotlib.pyplot as plt”?
- How to change the text color of font in legend?
- How to plot one single data point?
- Is there a matplotlib equivalent of MATLAB’s datacursormode?
- plotting a histogram on a Log scale with Matplotlib
- Xticks by pandas plot, rename with the string
- How to add title and xlabel and ylabel
- Plotting implicit equations in 3d