python - matplotlib fill_between does not cycle through colours -


most plotting methods plot() , errorbar automatically change next colour in color_palette when plot multiple things on same graph. reason not case fill_between(). know hard-code done in loop makes annoying. there way around this?

import numpy np import matplotlib.pyplot plt  x = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0]) y = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0]) xerr = np.asarray([0.2, 0.4, 0.6, 0.8, 1.0]) yerr = np.asarray([0.1, 0.2, 0.3, 0.4, 0.5])  plt.fill_between(x, y-yerr, y+yerr,alpha=0.5) plt.fill_between(y,x-xerr,x+xerr,alpha=0.5)  plt.show()  

maybe current position in palette , iterate next enough.

strange, seems calling ax._get_patches_for_fill.set_color_cycle(clist) or ax.set_color_cycle(np.roll(clist, -1)) explicitly doesn't reinstate color cycle (see answer). may because fill between doesn't create conventional patch or line object (or may bug?). anyway, manually call cycle on colors in axis function ax.set_color_cycle,

import numpy np import matplotlib.pyplot plt matplotlib import rcparams import itertools  clist = rcparams['axes.color_cycle'] cgen = itertools.cycle(clist)  x = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0]) y = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0]) xerr = np.asarray([0.2, 0.4, 0.6, 0.8, 1.0]) yerr = np.asarray([0.1, 0.2, 0.3, 0.4, 0.5])  fig, ax = plt.subplots(1,1) ax.fill_between(x, y-yerr, y+yerr,alpha=0.5, facecolor=cgen.next()) ax.fill_between(y,x-xerr,x+xerr,alpha=0.5, facecolor=cgen.next())  plt.show()  

Comments

Popular posts from this blog

html - height not adding height to a empty div -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

python - Robot Framework location and name of keyword -