def show_rgb_hist(image):
colours = ('r','g','b')
for i, c in enumerate(colours):
plt.figure(figsize=(20, 4))
histr = cv2.calcHist([image], [i], None, [256], [0, 256])
# plt.plot(histr, color=c, lw=2)
# print(histr.ravel())
if c == 'r':
colours = [((i/256, 0, 0)) for i in range(0, 256)]
if c == 'g':
colours = [((0, i/256, 0)) for i in range(0, 256)]
if c == 'b':
colours = [((0, 0, i/256)) for i in range(0, 256)]
plt.bar(range(0, 256), histr, color=colours, edgecolor=colours, width=1)
# plt.xlim([0, 256])
plt.show()
show_rgb_hist(image)
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-47-eb26539e3a3c> in <module>()
22 plt.show()
23
---> 24 show_rgb_hist(image)
<ipython-input-47-eb26539e3a3c> in show_rgb_hist(image)
17
18
---> 19 plt.bar(range(0, 256), histr, color=colours, edgecolor=colours, width=1)
20 # plt.xlim([0, 256])
21
~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in bar(*args, **kwargs)
2646 mplDeprecation)
2647 try:
-> 2648 ret = ax.bar(*args, **kwargs)
2649 finally:
2650 ax._hold = washold
~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1715 warnings.warn(msg % (label_namer, func.__name__),
1716 RuntimeWarning, stacklevel=2)
-> 1717 return func(ax, *args, **kwargs)
1718 pre_doc = inner.__doc__
1719 if pre_doc is None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in bar(self, *args, **kwargs)
2083 edgecolor=e,
2084 linewidth=lw,
-> 2085 label='_nolegend_',
2086 )
2087 r.update(kwargs)
~/anaconda3/lib/python3.6/site-packages/matplotlib/patches.py in __init__(self, xy, width, height, angle, **kwargs)
657 """
658
--> 659 Patch.__init__(self, **kwargs)
660
661 self._x = xy[0]
~/anaconda3/lib/python3.6/site-packages/matplotlib/patches.py in __init__(self, edgecolor, facecolor, color, linewidth, linestyle, antialiased, hatch, fill, capstyle, joinstyle, **kwargs)
101 self.set_fill(fill)
102 self.set_linestyle(linestyle)
--> 103 self.set_linewidth(linewidth)
104 self.set_antialiased(antialiased)
105 self.set_hatch(hatch)
~/anaconda3/lib/python3.6/site-packages/matplotlib/patches.py in set_linewidth(self, w)
349 w = mpl.rcParams['axes.linewidth']
350
--> 351 self._linewidth = float(w)
352 # scale the dash pattern by the linewidth
353 offset, ls = self._us_dashes
TypeError: only size-1 arrays can be converted to Python scalars
Plot rgb_hist
Error:
How can I solve this issue?