Navigation Menu

Skip to content
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

FIX: formatting in LogFormatterExponent #5594

Merged
merged 3 commits into from Dec 14, 2015

Conversation

tacaswell
Copy link
Member

The scale passed to the pprint_val method needs to also be
scaled by the log so that the range used to format the tick labels
matches the actual range of the tick labels (not the underlying values).

reported via http://stackoverflow.com/questions/33975758/matplotlib-logformatterexponent-e-in-the-exponent-labels-of-cbar

More coming on pprint_val

The scale passed to the `pprint_val` method needs to also be
scaled by the log so that the range used to format the tick labels
matches the actual range of the tick labels (not the underlying values).

reported via http://stackoverflow.com/questions/33975758/matplotlib-logformatterexponent-e-in-the-exponent-labels-of-cbar
@tacaswell tacaswell added this to the next bug fix release (2.0.1) milestone Dec 1, 2015
@tacaswell
Copy link
Member Author

Sigh, meant to target this against v2.0.x, oh well.

@tacaswell tacaswell modified the milestones: next major release (2.0), next bug fix release (2.0.1) Dec 1, 2015
Makes sure that there are never trailing 'e' with no exponent.
Code used to generate the test data to establish bench mark.

First print out is human-readable, second is for testing

import itertools
import matplotlib.ticker as mticker
import numpy as np

domains = sorted([1e-3, 1.5e-2, 1e6, 100, 5, .5])
float_values = sorted([np.pi * (10**i) for i in range(-5, 6)])
int_values = sorted([1 * (10 ** i) for i in range(-5, 6)])
fmt = mticker.LogFormatter()
print()
for d in domains:
    print('Domain ', d)
    for f in float_values:
        print('     {: >10.7f}: {: <10}'.format(f, fmt.pprint_val(f, d)))
    for f in int_values:
        print('     {: >10g}: {: <10}'.format(f, fmt.pprint_val(f, d)))

print()
print()

print(',\n'.join(['        ({v:.10g}, {d!r}, {res!r})'.format(
    v=f, d=d, res=fmt.pprint_val(f, d))
                  for d, f in itertools.product(
                          domains, float_values + int_values)]))
@tacaswell
Copy link
Member Author

Domain  0.001
      0.0000314: 3.142e-5  
      0.0003142: 3.142e-4  
      0.0031416: 3.142e-3  
      0.0314159: 3.142e-2  
      0.3141593: 3.142e-1  
      3.1415927: 3.142     
     31.4159265: 3.142e1   
     314.1592654: 3.142e2   
     3141.5926536: 3.142e3   
     31415.9265359: 3.142e4   
     314159.2653590: 3.142e5   
          1e-05: 1e-5      
         0.0001: 1e-4      
          0.001: 1e-3      
           0.01: 1e-2      
            0.1: 1e-1      
              1: 1         
             10: 10        
            100: 100       
           1000: 1000      
          10000: 1e4       
         100000: 1e5       
Domain  0.015
      0.0000314: 0         
      0.0003142: 0         
      0.0031416: 0.003     
      0.0314159: 0.031     
      0.3141593: 0.314     
      3.1415927: 3.142     
     31.4159265: 31.416    
     314.1592654: 314.159   
     3141.5926536: 3141.593  
     31415.9265359: 31415.927 
     314159.2653590: 314159.265
          1e-05: 0         
         0.0001: 0         
          0.001: 0.001     
           0.01: 0.01      
            0.1: 0.1       
              1: 1         
             10: 10        
            100: 100       
           1000: 1000      
          10000: 10000     
         100000: 100000    
Domain  0.5
      0.0000314: 0         
      0.0003142: 0         
      0.0031416: 0.003     
      0.0314159: 0.031     
      0.3141593: 0.314     
      3.1415927: 3.142     
     31.4159265: 31.416    
     314.1592654: 314.159   
     3141.5926536: 3141.593  
     31415.9265359: 31415.927 
     314159.2653590: 314159.265
          1e-05: 0         
         0.0001: 0         
          0.001: 0.001     
           0.01: 0.01      
            0.1: 0.1       
              1: 1         
             10: 10        
            100: 100       
           1000: 1000      
          10000: 10000     
         100000: 100000    
Domain  5
      0.0000314: 0         
      0.0003142: 0         
      0.0031416: 0         
      0.0314159: 0.03      
      0.3141593: 0.31      
      3.1415927: 3.14      
     31.4159265: 31.42     
     314.1592654: 314.16    
     3141.5926536: 3141.59   
     31415.9265359: 31415.93  
     314159.2653590: 314159.27 
          1e-05: 0         
         0.0001: 0         
          0.001: 0         
           0.01: 0.01      
            0.1: 0.1       
              1: 1         
             10: 10        
            100: 100       
           1000: 1000      
          10000: 10000     
         100000: 100000    
Domain  100
      0.0000314: 0         
      0.0003142: 0         
      0.0031416: 0         
      0.0314159: 0         
      0.3141593: 0.3       
      3.1415927: 3.1       
     31.4159265: 31.4      
     314.1592654: 314.2     
     3141.5926536: 3141.6    
     31415.9265359: 31415.9   
     314159.2653590: 314159.3  
          1e-05: 0         
         0.0001: 0         
          0.001: 0         
           0.01: 0         
            0.1: 0.1       
              1: 1         
             10: 10        
            100: 100       
           1000: 1000      
          10000: 10000     
         100000: 100000    
Domain  1000000.0
      0.0000314: 3.1e-5    
      0.0003142: 3.1e-4    
      0.0031416: 3.1e-3    
      0.0314159: 3.1e-2    
      0.3141593: 3.1e-1    
      3.1415927: 3.1       
     31.4159265: 3.1e1     
     314.1592654: 3.1e2     
     3141.5926536: 3.1e3     
     31415.9265359: 3.1e4     
     314159.2653590: 3.1e5     
          1e-05: 1e-5      
         0.0001: 1e-4      
          0.001: 1e-3      
           0.01: 1e-2      
            0.1: 1e-1      
              1: 1         
             10: 10        
            100: 100       
           1000: 1000      
          10000: 1e4       
         100000: 1e5       

These are now the results of pprint_val for all of the domains in a human-readable form.

@mdboom
Copy link
Member

mdboom commented Dec 1, 2015

👍

mdboom added a commit that referenced this pull request Dec 14, 2015
FIX: formatting in LogFormatterExponent
@mdboom mdboom merged commit c6dda2d into matplotlib:master Dec 14, 2015
mdboom added a commit that referenced this pull request Dec 14, 2015
FIX: formatting in LogFormatterExponent
@mdboom
Copy link
Member

mdboom commented Dec 14, 2015

Backported to 2.0.x as 7414cf0

@tacaswell tacaswell deleted the fix_logformatterexponent branch December 19, 2015 02:31
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Dec 19, 2015
…onent

FIX: formatting in LogFormatterExponent
@QuLogic
Copy link
Member

QuLogic commented Oct 16, 2016

Backport to v2.x is actually via 5ff7e37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants