1

I have been able to change the facecolor of a plot using basic colors, r,g,b etc. However, I am working on a project and I need to prepare a presentation that will be visually pleasing and I would like to use a wider range of colors, such as colors that are listed here. This is the code I am using (I want the area below the graph to be colored):

fig = plt.figure(num=None, figsize=(30, 50))
ax1 = fig.add_subplot(2,1,1)
ax1.plot(x, y, 'k-')
ax1.fill_between(x, min(y), y, facecolor='#8B0000')

However, facecolor does nothing when I use HEX colors, but it works when I use 'r','b' etc. Is there any way to use HEX color codes for fill_between?

Community
  • 1
  • 1
user20150316
  • 101
  • 2
  • 8

1 Answers1

2

According the docs facecolor accepts matplotlib color arg or sequence of rgba tuples. If you want to use hex colors you must first convert the hex value to correct format. Take a look at the matplotlib.colors module. I'm not fully familiar with the library but maybe hex2color is of use.

Martin
  • 2,135
  • 8
  • 39
  • 42
  • [Visualization of named colors](http://matplotlib.org/examples/color/named_colors.html) – Martin Mar 17 '15 at 16:15
  • Actually, this is not working. Even when I use converted hex, the color doesn't change. When I use hex for setting font color or anything else, it works fine, but doesn't work for facecolor. – user20150316 Mar 17 '15 at 16:37
  • 1
    it seems that something else is going in my code since this worked when I used it with a random plot – user20150316 Mar 17 '15 at 16:40