Use a single figure to generate histogram

This commit is contained in:
Benjamin Loison 2024-04-25 12:39:24 +02:00
parent ec3ddd9c94
commit e2602347d4
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -9,15 +9,6 @@ image.histogram()
HEX_COLOR = '#%02x%02x%02x'
def getRed(redIntensity):
return HEX_COLOR % (redIntensity, 0, 0)
def getGreen(greenIntensity):
return HEX_COLOR % (0, greenIntensity, 0)
def getBlue(blueIntensity):
return HEX_COLOR % (0, 0, blueIntensity)
def getColor(intensity, colorIndex):
return HEX_COLOR % tuple((intensity if colorIndex == colorIndexTmp else 0) for colorIndexTmp in range(3))
@ -28,17 +19,9 @@ red = histogram[0:COLOR_BASE]
green = histogram[COLOR_BASE:COLOR_BASE*2]
blue = histogram[COLOR_BASE*2:COLOR_BASE*3]
#for colorIndex, color in [red, green, blue]
plt.figure(0)
for i in range(0, COLOR_BASE):
plt.bar(i, red[i], color = getColor(i, 0),alpha=0.3)
plt.figure(1)
for i in range(0, COLOR_BASE):
plt.bar(i, green[i], color = getColor(i, 1),alpha=0.3)
plt.figure(2)
for i in range(0, COLOR_BASE):
plt.bar(i, blue[i], color = getColor(i, 2),alpha=0.3)
for colorIndex, color in enumerate([red, green, blue]):
#plt.figure(colorIndex)
for i in range(COLOR_BASE):
plt.bar(i, color[i], color = getColor(i, colorIndex), alpha = 0.3)
plt.show()