Is there a way to save matplotlib graphs without the border around the frame while keeping the background not transparent?
Setting the frame to 'off' as I show in the code below does not work as this removes the background making it transparent whereas I want to retain the white background, just without the borders.
a = fig.gca()
a.set_frame_on(False)
Here is a screenshot of what I'm trying to do. If the border can be removed then I can draw the x-axis line separately.
All suggestions are much appreciated.
A simpler way:
import matplotlib.pyplot as plt
plt.tick_params(left=False, labelleft=False) #remove ticks
plt.box(False) #remove box
A similar question was asked here: How can I remove the top and right axis in matplotlib?. A Google search for "hide axes matplotlib" gives that as the 5th link.
Remove the spines:
x = linspace(0, 2 * pi, 1000)
y = sin(x)
fig, ax = subplots()
ax.plot(x, y)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.grid(axis='y')
You can try to use ax.spines
. For example:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
If you want to remove all spines (and probably ticks as well), you can do
[s.set_visible(False) for s in ax.spines.values()]
[t.set_visible(False) for t in ax.get_xticklines()]
[t.set_visible(False) for t in ax.get_yticklines()]
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