0

I generate a graph with the following code:

# Initialize fig & axis objects
fig, ax1 = plt.subplots(1, 1, sharex=True)

# Add second y-axis
ax2=ax1.twinx()

# Create 4 legends
ln0 = ax2.plot([0,100], [80.5, 80.5],color='darkgreen',label='Y_axis-2')
ln1 = ax1.plot([0,100],[79,79], color='darkred', label='Y_axis-1a')
ln2 = ax1.plot([0,100],[80.5,80.5], color='darkorange', label='Y_axis-1b')
ln3 = ax1.plot([0,100],[81,81], color='darkblue', label='Y_axis-1c')
lns = ln0 + ln1 + ln2 + ln3
labs = [l.get_label() for l in lns]

# Add legends to graph
ax1.legend(lns, labs, bbox_to_anchor=(0.65,0.45))

# Label axes
ax1.set_xlabel('X-axis', fontsize=12)
ax1.set_ylabel('Y1-Axis', fontsize=12)
ax2.set_ylabel('Y2-Axis', fontsize=12)

# Make and save plot
plt.title('Title')
plt.tight_layout()
plt.savefig("dummy.png", bbox_inches='tight')

I see the following image in my jupyter notebook:

enter image description here

However, when I open/view the saved png file, I see this:

enter image description here

Why don't my title, axis labels and axis tick values show up against a white background, instead of a dark or neutral one?

user1245262
  • 6,968
  • 8
  • 50
  • 77
  • `plt.rcParams['savefig.facecolor'] = 'white'` – Trenton McKinney Oct 07 '21 at 00:30
  • I think this may be caused by the different GUI environment in the OS you are using. Please refer to the detailed explanation [here](https://matplotlib.org/stable/tutorials/introductory/usage.html). – r-beginners Oct 07 '21 at 01:39

0 Answers0