Home > Software design >  Remove the jaggedness
Remove the jaggedness

Time:01-08

I'm trying to plot a Spirograph™ curve

In [65]: from matplotlib.pyplot import gca, subplots
    ...: from numpy import exp, lcm, linspace, pi
    ...: 
    ...: def prepare_for_sg():
    ...:     fig, ax = subplots()
    ...:     ax.set_aspect(1)
    ...:     ax.axis(False)
    ...:     return fig, ax
    ...: 
    ...: def plot_sg(R, r, d, Φ=0.0, φ=0.0, ax=None):
    ...:     if ax is None : ax = gca()
    ...:     Ω = 2*pi ;  ω = -Ω*R/r
    ...:     n = lcm(r, R)
    ...:     t = linspace(0, n, n*360 1)
    ...:     xy = (R-r)*np.exp(1j*Ω*(t-Φ))   d*np.exp(1j*ω*(t-φ))
    ...:     line, = ax.plot(xy.real, xy.imag)
    ...:     line.set_antialiased(True)
    ...: 
    ...: prepare_for_sg() ; plot_sg(56, 42, 13)

In [66]: !xmag

and below it's what I get, plus an xmag window zooming on a detail of the curve — there is no excess of antialiasing.

What should I do to remove the jaggedness?


PS the PNG image that I inserted in my question IS ANTIALIASED, because of the conversion and scaling operated by SO.

enter image description here

CodePudding user response:

matplotlib renders the graph for your screen, so in the end, this is like a bitmap. There will always be some form aliasing in this case.

I assume you want a graph without aliasing to process it further, maybe printing it with high detail? Then you could plt.savefig("output.pdf"), which would save it as PDF with vector graphics.

CodePudding user response:

try to modify figure size and linewidth

    line, = ax.plot(xy.real, xy.imag,linewidth=5.0) #line width
    fig = plt.gcf()
    fig.set_size_inches(30, 30) #set figure size

example

  •  Tags:  
  • Related