Skip to content

linscalex/linscaley (for symlog) behaviour and documentation #10369

Closed as not planned

Description

@gregcolyer

According to the documentation linscalex/linscaley "is the number of decades to use for each half of the linear range." This may be correct for base 10* (incidentally the documentation does not specify that this is the default base) but with a general base b it seems not to be, nor for a 'b-ade' as opposed to a decade. Also, there is a natural value log(e)/log(b) for this scaling (relative to the 'b-ade') which makes the scale continuous at the threshold and hence does not introduce gradient jumps in smooth curves. This may be a better default than 1.

import matplotlib.pyplot as plt
import numpy as np

b = 2.  # Try 100. too
t = 1.

# Define some curves:
x = np.linspace(0.1,3.,100)
y1 = x
y2 = x**2
y3 = np.exp(x)/2.
y4 = np.log(x)*2.

plt.figure()

plt.subplot(1,3,1)
plt.title('base 10 default')
plt.ylim(-100,100)
plt.yscale('symlog',linthreshy=t)               # should set decade = half-linear
plt.plot(x,y1)
plt.plot(x,y2)
plt.plot(x,y3)
plt.plot(x,y4)

plt.subplot(1,3,2)
plt.title('base 10 smooth?')
plt.ylim(-100,100)
plt.yscale('symlog',linthreshy=t,linscaley=np.log10(np.e))      # smooth match?
plt.plot(x,y1)
plt.plot(x,y2)
plt.plot(x,y3)
plt.plot(x,y4)

plt.subplot(1,3,3)
plt.title('base %d default' % (b))
plt.ylim(-100,100)
plt.yscale('symlog',linthreshy=t,basey=b)       # doesn't set decade or b-ade = half-linear
plt.plot(x,y1)
plt.plot(x,y2)
plt.plot(x,y3)
plt.plot(x,y4)

plt.show()

Linux; matplotlib 2.0.0, python 2.7.12 via conda

*actually not; see below

Activity

  1. gregcolyer commented on Feb 2, 2018

    @gregcolyer
    Author

    On further investigation inspired by issue #7008, it appears that _linscale_adj is indeed the culprit. Premultiplying by (1 - 1/b), i.e. the inverse of the adjustment factor, seems to eliminate the discrepancies and also reveals that it means "the number of b-ades" (not decades) in general. Suggest the following three actions:

    1. Remove this adjustment factor; or at least (if it is needed for some other purpose) document both it and the above fix, and perhaps provide a parameter to perform the fix automatically
    2. In the documentation, change decade to b-ade for a general base b
    3. Consider changing the default value from 1 to log(e)/log(b)
  2. gregcolyer commented on Feb 2, 2018

    @gregcolyer
    Author

    Note that with these changes, apart from tick labelling the default appearance would not depend on base.

    There are various equivalent choices that could be made instead of actions 2 and 3, e.g. a factor 1/log10(b) could be incorporated into the code so that linscalex/linscaley really does mean decade (as the documentation now says), and the default changed to log10(e) if desired; or a factor 1/ln(b) could be incorporated and the default left as 1 (but then the documentation should say whatever an 'e-ade' is called). Action 3 above or this second variant (but without reference to the documentation) was proposed as item 2 of issue #2288, but that issue seems to have been closed after only item 1 was done.

    Minimally either the documentation or the code needs to change; but preferably both.

  3. jgehrcke commented on Jun 26, 2019

    @jgehrcke
    Contributor

    Just a user who ran into this topic. Thank you for documenting your insights.

  4. gregcolyer commented on Jul 19, 2019

    @gregcolyer
    Author

    Cheers. The documentation does now state that the default base is 10, but the rest is probably still outstanding.

  5. github-actions commented on May 1, 2023

    @github-actions

    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!

  6. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on May 31, 2023
  7. rcomer commented on May 31, 2023

    @rcomer
    Member

    I’m going to re-open this one: the problem was clearly described with a reproducing example, so it would be good to at least check whether it still exists.

  8. reopened this on May 31, 2023
  9. removed
    status: inactiveMarked by the “Stale” Github Action
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on May 31, 2023
  10. rcomer commented on May 31, 2023

    @rcomer
    Member

    The API has moved on a little, so I think the code in the OP should now be like this (I also added a legend):

    import matplotlib.pyplot as plt
    import numpy as np
    
    plt.rcdefaults()
    
    b = 2.  # Try 100. too
    t = 1.
    
    # Define some curves:
    x = np.linspace(0.1,3.,100)
    y1 = x
    y2 = x**2
    y3 = np.exp(x)/2.
    y4 = np.log(x)*2.
    
    fig = plt.figure(layout='constrained')
    
    plt.subplot(1,3,1)
    plt.title('base 10 default')
    plt.ylim(-100,100)
    plt.yscale('symlog',linthresh=t)               # should set decade = half-linear
    plt.plot(x,y1)
    plt.plot(x,y2)
    plt.plot(x,y3)
    plt.plot(x,y4)
    
    plt.subplot(1,3,2)
    plt.title('base 10 smooth?')
    plt.ylim(-100,100)
    plt.yscale('symlog',linthresh=t,linscale=np.log10(np.e))      # smooth match?
    plt.plot(x,y1)
    plt.plot(x,y2)
    plt.plot(x,y3)
    plt.plot(x,y4)
    
    plt.subplot(1,3,3)
    plt.title('base %d default' % (b))
    plt.ylim(-100,100)
    plt.yscale('symlog',linthresh=t,base=b)       # doesn't set decade or b-ade = half-linear
    plt.plot(x,y1, label='y = x')
    plt.plot(x,y2, label='y = x**2')
    plt.plot(x,y3, label='y = (e**x)/2')
    plt.plot(x,y4, label='y = log(x) * 2')
    
    fig.legend(loc='outside lower center', mode='expand', ncols=4)
    
    plt.show()

    Using main:

    test

    Things to note

    • As OP points out, setting linscale=np.log10(np.e) in the middle plot does produce smooth curves. OP suggests that would therefore be a better default, though the current default is clearly simpler.
    • The linear range between y=-1 and y=1 on the base 2 plot (right) is smaller than the documented 2 decades in the log range and also larger than 2 powers of 2 in the log range.
  11. github-actions commented on Jul 3, 2024

    @github-actions

    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!

  12. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Aug 2, 2024
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

    Documentationstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions