-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] savefig cannot generate high resolution output as is rendered #3360
Comments
I think it is rendering problem. Repl figures are svg as I believe. Perhaps try saving with svg format and see it happens again? |
I have tried svg just now.Same glitch appears. |
I think glitches are expected as you are trying to plot a diverging function. The closer you get to zero the more uncertain it is. I suggest you to plot to a certain cutoff near zero, and then call it zero past it. This is purely a numerical issue. |
Maybe your function needs to have a slightly wider zero region? function f(x)
if abs(x) < 0.001
return 0; end
x^2 * sin(1/x)
end |
This function in fact converge to 0 as x approaches to 0 although it oscillating faster and faster. This is what make this function interesting and serves as a classical example as a function with discontinuous derivative in mathematical analysis. As for your suggestion, in fact glitch begins to appear at around 0.004 which is not too small because I just plot the function on the internal -0.02 to 0.02. 0.004 is 1/10 of the length of the interval. I don't think I should add a zero region because this solution loss the interesting part of the functions. I can produce the same plot using the Python code attached bellow, but do not observe glitch either in svg or png format. import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-0.02, 0.02, 0.000001)
def f(x):
if x==0:
return 0
else:
return x**2 * np.sin(1/x)
f=np.vectorize(f)
plt.plot(x, f(x))
plt.title(r"$x^2 \sin(1/x)$")
plt.show()
plt.savefig("pyfx.svg", format="svg")
plt.savefig("pyfx.png", format="png") Different SVG saving formatOne thing that might be useful for you is that I open the Julia
Python
Some sample picturePlots.jl GR backendmatplotlib - use Python |
I think I have found it is the setting of Since I am not an SVG expert I can only provide the process I find it. If I modified this property from Is there a special reason for preferring |
PyPlot uses miter because GR does, but if GR could use round, I think it not only looks better but also avoids this behavour |
It seems that GR and pyplot use round join now so this issue has been solved. GR.jl 0.57.5 (with GR run-time 0.57.3). |
Details
I plot a graph of a function and save it with
savefig
.I save it in
png
andpdf
format, but find that both outputs have some very strange glitch aroundx=0
I also try various parameters setting such as
but none of them can have any effect on the quality of the
savefig
output.I try
GR
andPyplot
backends. Both give similar phenomenon.You can see the difference by comparing the following two pictures:
screenshot
It is exacly what I want and what the function looks like.
savefig
outputBackends
This bug occurs on ( insert
x
below )Versions
Plots.jl version:
Backend version (
]st -m
):Output of
versioninfo()
:The text was updated successfully, but these errors were encountered: