Matplotlib 设置子图的面色

Matplotlib set facecolor of a subplot

我已经能够使用基本颜色、r、g、b 等更改绘图的面色。但是,我正在做一个项目,我需要准备一个视觉上令人愉悦的演示文稿,我会喜欢使用范围更广的颜色,例如 here 列出的颜色。这是我正在使用的代码(我希望图表下方的区域是彩色的):

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')

但是,当我使用 HEX 颜色时,facecolor 什么都不做,但是当我使用 'r'、'b' 等时它会起作用。有没有办法为 fill_between 使用 HEX 颜色代码?

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有用