Python: strange behavior with matplotlib barchart

advertisements

I have a strange behavior using matplotlib in an ipython notebook: when I change the attribute "color" of the barchart, the result is ugly, I have some bars in red and some others in black. This is happening only when I have a high amount of bars to display (>100).

You can execute the code below to reproduce the problem, playing with the dataPoints parameter to see the effect of the number of bars:

import random
import matplotlib.pyplot as plt

dataPoints = 400
data = random.sample(range(300, 1000), dataPoints)
xCoords = range(dataPoints)

fig = plt.figure(figsize=[13,9])
plt.bar(xCoords,data,color='red')
plt.show()

Here is an example of the result :


If you zoom in on the bars, you will see that actually, there are no black bars. The black you see is the result of the black border around the bars and interpolation to fit the pixels of your screen.

What you can do to have only red in your image is changing the color of the border to red using

plt.bar(xCoords, data, color='red', edgecolor='red')