Home > other >  Bidirectional Bar Plot in python, how to remove all background colours?
Bidirectional Bar Plot in python, how to remove all background colours?

Time:11-02

I wrote this code (using enter image description here

I want to remove all the background colours (so there's no 'Figure 1', no white gridlines and the background is pure white instead of blue-y purple), and then just add a black line on the x and y axis.

When I try to add an x and y axis line with this:

plt.update_xaxes(showline=True, linewidth=2, linecolor='black')
plt.update_yaxes(showline=True, linewidth=2, linecolor='black')

There's no error, but there's no graph either.

Edit 1: Adding

axes[0].set_facecolor('white')
axes[1].set_facecolor('white')

Worked for removing the background colours. I also tried to add x and y axis lines via:

axes[0].axvline(0)
axes[0].axhline(0)

This produces a line mid-way through the bottom bar:

enter image description here

(and 'Figure 1' is still there).

CodePudding user response:

The parameter facecolor is responsible for the background color. You can remove it to have white background.

Use set_window_title to add a new title to the window.

Modified code looks like this:

fig, axes = plt.subplots(figsize=(10,5), ncols=2,sharey=True) # Removed facecolor param
fig.tight_layout()
fig.canvas.set_window_title('Custom Title') # Adds new title to the window
  • Related