When plotting in a cycle - the columns change color with each call. Can anyone tell what the reason? That is, I want to understand the strange behavior of matplotlib.

import matplotlib.pyplot as plt from matplotlib import mlab fig = plt.figure() ax4 = fig.add_subplot(111) ax4.set_xlim(-10,80) ax4.set_ylim(0,30) def view(ylist): xmin = 0 xmax = 70.0 # Шаг между точками dx = 10 xlist = mlab.frange (xmin, xmax, dx) ax4.bar(xlist, ylist, dx) plt.pause(0.5) plt.draw() ylist = [0 for p in range(8)] for i in range(10): view(ylist) ylist[0] +=1 ylist[3] +=2 plt.close() 
  • 3
    It's simple, matplotlib believes that you are drawing new graphics over old ones, and accordingly gives them a new color. Add to the loop before calling the view function a call to the plt.cla() method. - Avernial
  • @Avernial - thank you! This is the answer) - Vasyl Kolomiets

0