Kit Kit - 1 year ago 33
Python Question

How do I make bar plots automatically cycle across different colors?


, line plots color cycle automatically. These two line plots would have different colors.

axes.plot(x1, y)
axes.plot(x2, y)

However, bar plots don't. Both these data series will have blue bars., y), y)

How do I make bar plots cycle automatically across a predefined set of colors?

Answer Source

Would something along these lines do it for you?

from matplotlib import cm
import matplotlib.pyplot as plt


for i in range(0,len(x)):[i],y[i],color=cm.jet(1.*i/len(x)))

More on colormaps.

EDIT: See this example for how to cycle over a predefined set of colors.