0

I am using jupyter notebook for simple plotting tasks as the following.

%matplotlib inline

plt.rcParams["figure.figsize"] = (12, 8)
plt.style.use("bmh")

I am getting a plot of the following form. How can remove the background silver color (we can keep the grid but I can also turn them off using plt. grid(False)) to white and change the border color of the plot to black?

enter image description here

2 Answers 2

1

The "bmh" style sets the axes facecolor and edgecolor like

axes.facecolor: eeeeee
axes.edgecolor: bcbcbc

You can set them back after setting the style,

import matplotlib.pyplot as plt

plt.style.use("bmh")
plt.rcParams.update({"figure.figsize" : (12, 8),
                     "axes.facecolor" : "white",
                     "axes.edgecolor":  "black"})
Sign up to request clarification or add additional context in comments.

2 Comments

Concerning your (now deleted) comment about the legends, I would reading this and this
I sorted it out and that's why I deleted it but thank you!
1

I would recommend the following way. The following answer is based on this and this posts

%matplotlib inline

plt.rcParams["figure.figsize"] = (8, 6)
plt.style.use("bmh")

plt.hist(np.random.normal(0,1, 10000), bins=100)
plt.gca().set_facecolor("white")
plt.setp(ax.spines.values(), color='k') # Change the frame border to black ('k')

An alternative way using ax object could be

%matplotlib inline

plt.rcParams["figure.figsize"] = (8, 6)
plt.style.use("bmh")

fig, ax = plt.subplots()

ax.hist(np.random.normal(0,1, 10000), bins=100);
ax.set_facecolor("white")
plt.setp(ax.spines.values(), color='k')

enter image description here

1 Comment

thank you so much. But how about without creating a new figure handler (` fig, ax = plt.subplots()? Is there any way to set the border color to black with plt`?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.