I'm successfully using Python and Matplotlib to create transparent PNG figures that look good when I add the plots to a Powerpoint slide that has a white background. Below is an example:
However, when I use a presentation slide deck that has a black background, the figure does not look as good. The text font and lines are all black, and they blend right into the background.
Is there a quick and easy way to generate these figures so that they will look good on a black slide? For example, I'd like to quickly make all the lines and text white. I know I can individually set the colors for the title, axis labels, axis values, etc., but is there a "master theme" for quickly making this kind of change?
Here is what my code generally looks like:
_ = plt.bar(hours, series_two, label='One')
_ = plt.bar(hours, series_one, label='Two')
_ = plt.grid()
_ = plt.xticks(range(0,24))
_ = plt.yticks(np.arange(0, 1.01, 0.05))
_ = plt.ylim(0, 1.0)
_ = plt.xlabel('Hour of day')
_ = plt.ylabel('Value')
_ = plt.tight_layout()
_ = plt.title('Experimental results')
_ = plt.legend()
_ = plt.show()
EDIT: I used plt.style.use("dark_background")
from the related questions, but the results look terrible. I just want to change the lines and text, not the colors of the bars.
To plot black-and-white binary map in matplotlib, we can create and add two subplots to the current figure using subplot() method, where nrows=1 and ncols=2. To display the data as a binary map, we can use greys colormap in imshow() method.
The usual way to set the line color in matplotlib is to specify it in the plot command. This can either be done by a string after the data, e.g. "r-" for a red line, or by explicitely stating the color argument.
If the predesigned dark_background
style does not match the expectations, one may set the respective rcParams manually. The following might produce the desired plot.
import matplotlib.pyplot as plt
plt.rcParams.update({
"lines.color": "white",
"patch.edgecolor": "white",
"text.color": "black",
"axes.facecolor": "white",
"axes.edgecolor": "lightgray",
"axes.labelcolor": "white",
"xtick.color": "white",
"ytick.color": "white",
"grid.color": "lightgray",
"figure.facecolor": "black",
"figure.edgecolor": "black",
"savefig.facecolor": "black",
"savefig.edgecolor": "black"})
x = range(1,25)
y = range(60,108)[::-2]
y2 = range(16,40)[::-1]
plt.bar(x, y, label='One')
plt.bar(x, y2, label='Two')
plt.grid()
plt.xticks(x)
plt.xlabel('Hour of day')
plt.ylabel('Value')
plt.title('Experimental results', color="w")
plt.legend()
plt.tight_layout()
plt.show()
Note that you would need to set the title color manually, because the default text color is set to black, such that the legend text is black. Else, one could of course do the inverse and set the legend text color manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With