Skip to content

scatterplot axis autoscale fails for small data values #6015

Closed

Description

@ariekahn

I'm finding that the scatterplot autoscaling fails when plotting small values, e.g. <0.001.

The autoscale axis range will never go below -0.008 to 0.008 for me, regardless of how small the range of the data being plotted.

plt.figure()
x = np.array([0,1,2,3])
x = np.array([2,4,5,9])
plt.scatter(x,y)

Data in a normal range produces
properly_scaled

plt.figure()
x = np.array([0,1,2,3])
x = np.array([2,4,5,9])
plt.scatter(x/10000,y/10000)

While scaling it down produces
badly_scaled

Activity

  1. added this to the milestone on Feb 18, 2016
  2. tacaswell commented on Feb 18, 2016

    @tacaswell
    Member

    On 2.x it seems to go to pm 0.002.

    I assume this is due to the non-singular expanding logic?

  3. modified the milestones: , on Mar 21, 2016
  4. added a commit that references this issue on Mar 21, 2016
    8b5d9e2
  5. self-assigned this
    on Mar 21, 2016
  6. dstansby commented on Jan 29, 2017

    @dstansby
    Member

    ping @mdboom, I may be wrong, but the referenced commit above doesn't relate to this bug?

  7. modified the milestones: , on May 3, 2017
  8. removed this from the milestone on Oct 9, 2017
  9. 1 remaining item

  10. ImportanceOfBeingErnest commented on Jul 12, 2018

    @ImportanceOfBeingErnest
    Member

    This problem is still present in current master.

  11. FraserParlane commented on Jan 5, 2019

    @FraserParlane

    Apart from manually scaling, is there a workaround for this issue?

  12. LindyBalboa commented on Jan 5, 2019

    @LindyBalboa
    Contributor
  13. trbedwards commented on Jan 11, 2019

    @trbedwards

    If you still want the scatter functionality and have autoscale working, there's a good workaround I found on stackoverflow where you create an invisible plot after scatter:

    import matplotlib.pyplot as plt
    
    y=  [1.09E-05,  1.63E-05,   2.45E-05,   3.59E-05,   5.09E-05,   6.93E-05,   9.07E-05]
    x=  [0, 10, 20, 30, 40, 50, 60]
    
    fig3, ax3 = plt.subplots()
    ax3.scatter(x, y, color='k', marker = "o")
    ax3.plot(x, y, color='none')
    ax3.relim()
    ax3.autoscale_view()
    plt.show()
    
  14. ImportanceOfBeingErnest commented on Dec 17, 2019

    @ImportanceOfBeingErnest
    Member

    Closing as fixed by #13642

  15. modified the milestones: needs sorting, v3.2.0 on Dec 21, 2019
  16. geyang commented on Jan 19, 2020

    @geyang

    Has this problem with 3.1.2.

  17. jklymak commented on Jan 19, 2020

    @jklymak
    Member

    #13642 will be in 3.2

  18. moloney commented on Feb 14, 2020

    @moloney

    I installed the 3.2.0rc3 package, and I can confirm that this fixes almost all the issues with autoscaling and scatter. However, if you have points with 0 for the y-axis and enable log scaling there is still an issue with the scatter plot auto scaling (that doesn't show up with the standard plot function).

    import itertools
    
    import numpy as np
    from matplotlib import pyplot as plt
    
    
    x_vals = [4.38462e-06,
              5.54929e-06,
              7.02332e-06,
              8.88889e-06,
              1.125e-05,
              1.42383e-05,
              1.80203e-05,
              2.2807e-05,
              2.88651e-05,
              3.65324e-05,
              4.62363e-05,
              5.85178e-05,
              7.40616e-05,
              9.37342e-05,
              0.000118632,
              ]
    
    y_vals = [0.0,
              0.10000000000000002,
              0.182,
              0.332,
              0.604,
              1.1,
              2.0,
              3.64,
              6.64,
              12.100000000000001,
              22.0,
              39.60000000000001,
              71.3,
              ]
    
    pts = np.array(list(itertools.product(x_vals, y_vals)))
    
    fig = plt.figure("Scatter plot")
    ax = fig.gca()
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.scatter(pts[:,0], pts[:,1]) # This only shows four rows of points
    
    fig = plt.figure("Regular plot")
    ax = fig.gca()
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.plot(pts[:,0], pts[:,1], marker="o", ls="") # This works
    
    plt.show()
  19. jklymak commented on Feb 15, 2020

    @jklymak
    Member

    Can you open this as a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions