Cómo establecer la opacidad del color de fondo del gráfico con Matplotlib


He estado jugando con Matplotlib y no puedo averiguar cómo cambiar el color de fondo del gráfico, o cómo hacer que el fondo sea completamente transparente.

Author: Chris Seymour, 2011-01-03

1 answers

Si solo desea que todo el fondo para la figura y los ejes sean transparentes, simplemente puede especificar transparent=True al guardar la figura con fig.savefig.

Ej:

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(range(10))
fig.savefig('temp.png', transparent=True)

Si desea un control más detallado, simplemente puede establecer los valores facecolor y/o alfa para el parche de fondo figura y ejes. (Para hacer un parche completamente transparente, podemos establecer el alfa a 0, o establecer el facecolor a 'none' (como una cadena, no el objeto None!))

Ej:

import matplotlib.pyplot as plt

fig = plt.figure()

fig.patch.set_facecolor('blue')
fig.patch.set_alpha(0.7)

ax = fig.add_subplot(111)

ax.plot(range(10))

ax.patch.set_facecolor('red')
ax.patch.set_alpha(0.5)

# If we don't specify the edgecolor and facecolor for the figure when
# saving with savefig, it will override the value we set earlier!
fig.savefig('temp.png', facecolor=fig.get_facecolor(), edgecolor='none')

plt.show()

texto alt

 84
Author: Joe Kington,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-16 21:01:42