1

I am trying to reproduce a graph that shows the hue distribution of an image using an HSV colormap.

I have the information related to the hue channel represented as a dict, aggregated on multiple samples:

hue = {
    0 : hue_0,
    1 : hue_1,
    ...
  255 : hue_255
}

I have tried to use matplotlib's colorline example from here in the following way:

import matplotlib.pyplot as plt

x = list(hue.keys())
y = list(hue.values())

fig, ax = plt.subplots()
lc = colorline(x, y, cmap='hsv')
plt.colorbar(lc)
plt.xlim(0, 255)
plt.ylim(0, max(y))
plt.show()

but it produced this.

I have figured how to plot the hue dict as a line:

import matplotlib.pyplot as plt

lists = sorted(hue.items())

x, y = zip(*lists)

plt.plot(x, y)
plt.show()

But I cannot figure out how to add an HSV colormap to the plot.

  • I couldn't find any documentation on matplotlib about colorline. Is it a custom function or part of a different library? – Orozco Mar 23 '21 at 10:10
  • Maybe it is related to matplotlib's [multicolored line example](https://matplotlib.org/stable/gallery/lines_bars_and_markers/multicolored_line.html)? – JohanC Mar 23 '21 at 10:14
  • The colorline example is from here: https://stackoverflow.com/questions/36074455/python-matplotlib-with-a-line-color-gradient-and-colorbar – gallivantingitalian Mar 23 '21 at 10:19
  • Wouldn't calling `colorline(x, y, cmap='hsv')` on the sorted `x` and `y` do the job? – JohanC Mar 23 '21 at 10:41

0 Answers0