Issue
I save an image as .svg file and the plot is outside of the canvas boundaries. It does not happen with png files. Below is the code. Does anyone know the reason for that? I can fix it of course by truncating the data, but it is cumbersome. (Unfortunately svg file is not allowed to be uploaded here? So I uploaded a screenshot of the output as png)
%matplotlib qt
fig, ax = plt.subplots(constrained_layout=True)
xmin,xmax= 350,800
# ############################################################################################################
x = np.arange(200,900,1)
y = np.random.rand(len(x))
ax.plot(x,y,label="noise")
#############################################################################################################
leg = ax.legend(loc="upper right")
ax.set_ylim(-0.02,2)
ax.set_xlim(xmin,xmax)
plt.show()
I expected that ax.set_xlim(xmin,xmax) would be the boundaries for drawing, no matter what file type the plot is saved as.
Sidenote: The reason I use svg, is that I want to have a vector based graphic to use with Impress | LibreOffice. Id also use Powerpoint, but it does not seem to work with vector based graphics? Maybe I should use different file types anyways?
Solution
Change the plot statement to
ax.plot(x,y,label="noise",clip_on=True)
Answered By - lastchance
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.