Answers for "plot numpy histogram python"

13

matplotlib histogram

import matplotlib.pyplot as plt
data = [1.7,1.8,2.0,2.2,2.2,2.3,2.4,2.5,2.5,2.5,2.6,2.6,2.8,
        2.9,3.0,3.1,3.1,3.2,3.3,3.5,3.6,3.7,4.1,4.1,4.2,4.3]
#this histogram has a range from 1 to 4
#and 8 different bins
plt.hist(data, range=(1,4), bins=8)
plt.show()
Posted by: Guest on March-15-2020
0

numpy image histogram plot

# tuple to select colors of each channel line
colors = ("red", "green", "blue")
channel_ids = (0, 1, 2)

# create the histogram plot, with three lines, one for
# each color
plt.xlim([0, 256])
for channel_id, c in zip(channel_ids, colors):
    histogram, bin_edges = np.histogram(
        image[:, :, channel_id], bins=256, range=(0, 256)
    )
    plt.plot(bin_edges[0:-1], histogram, color=c)

plt.xlabel("Color value")
plt.ylabel("Pixels")

plt.show()
Posted by: Guest on August-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language