Skip to content

Plotted lines not symmetrical #8746

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

Closed
endolith opened this issue Jun 11, 2017 · 7 comments
Closed

Plotted lines not symmetrical #8746

endolith opened this issue Jun 11, 2017 · 7 comments
Labels
status: duplicate status: inactive Marked by the “Stale” Github Action

Comments

@endolith
Copy link
Contributor

endolith commented Jun 11, 2017

Bug report

Bug summary

I tried to reproduce this figure, but when I plotted using lines and dots, the dots are in the correct place, but the lines are slightly out of place, making things asymmetrical.

Code for reproduction

from scipy.special import iv
import numpy as np


def discrete_gaussian_kernel(n, t):
    T = np.exp(-t) * iv(n, t)
    return T


def sampled_gaussian_kernel(n, t):
    G = 1/np.sqrt(2*np.pi*t) * np.exp(-n**2/(2*t))
    return G

if __name__ == '__main__':
    import matplotlib.pyplot as plt

    plt.figure(figsize=(4, 5))
    for t in (0.5, 1, 2, 4):
        N = 6
        n = np.arange(-N, N+1)
        p = plt.plot(n, discrete_gaussian_kernel(n, t),  '.-', label=t)[0]
        plt.plot(n, sampled_gaussian_kernel(n, t),  ':', color=p.get_color())
    plt.grid(True)
    plt.ylim(0, 0.7)
    plt.xlim(-6, 6)
    plt.legend()

Actual outcome

figure_1

The dots look offset on the legend:

2017-06-11 12_41_54- figure_1 imported -1 0 rgb color 1 layer 400x496 gimp

But I guess it's actually the lines that are offset and asymmetrical:

asymmetrical

Expected outcome

If I save as SVG and open in Firefox, it looks fine:

svg in firefox

firefox dot

firefox symmetry

Matplotlib version

  • Operating System: Windows 7 Pro 64-bit
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.0
  • Jupyter Version (if applicable): IPython 5.1.0

This is inside Spyder 3.1.4 installed from default Anaconda channel, with graphics backend set to "automatic":

2017-06-11 12_51_28-preferences

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Jun 12, 2017
@tacaswell
Copy link
Member

Turning the DPI up to 100 will help.

This is a feature of the Agg backend which will 'snap' to the nearest pixel which makes the lines look 'sharper' assuming that 1 pixel is very small. This has been the behavior of the Agg backend for a while but it is getting noticed a lot more recently (not sure if it is all the high-dpi screens leading to more up-sampling or the larger defaults making it more obvious).

@endolith
Copy link
Contributor Author

Is there a way to turn this feature off? Changing the DPI in the settings of Spyder doesn't fix the interactive display.

@anntzer
Copy link
Contributor

anntzer commented Jun 16, 2017

The gtk3cairo (any cairo backend, I guess) backend does not suffer from this issue. I have been thinking of refactoring the backends so that one could also have {qt{4,5},wx,tk}cairo backends with minimal effort...

@tacaswell
Copy link
Member

Digging into this is on my 'few days of work' project list...

Setting the path.snap rcparam to False make help (but I have not tested).

@anntzer
Copy link
Contributor

anntzer commented Jun 17, 2017

path.snap = false does not help.
I have a working qtcairo backend, will make a PR soon.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 13, 2023
@anntzer
Copy link
Contributor

anntzer commented Apr 13, 2023

Closing as a duplicate of #7233, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

3 participants