Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

python - Borderless matplotlib plots

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.

enter image description here

All suggestions are much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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')

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...