FIX: formatting in LogFormatterExponent #5594

Merged
merged 3 commits into from Dec 14, 2015

Conversation

Projects
None yet
3 participants
Owner

tacaswell commented Dec 1, 2015

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

@tacaswell tacaswell FIX: formatting in LogFormatterExponent
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
7e3ef7d

tacaswell added this to the next bug fix release (2.0.1) milestone Dec 1, 2015

Owner

tacaswell commented Dec 1, 2015

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

tacaswell added some commits Dec 1, 2015

@tacaswell tacaswell MNT: clean up exponents in simpler way
Makes sure that there are never trailing 'e' with no exponent.
7566447
@tacaswell tacaswell TST: shotgun testing of LogFormatter.pprint_val
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)]))
f9c8aa1
Owner

tacaswell commented Dec 1, 2015

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.

Owner

mdboom commented Dec 1, 2015

👍

@mdboom mdboom added a commit that referenced this pull request Dec 14, 2015

@mdboom mdboom Merge pull request #5594 from tacaswell/fix_logformatterexponent
FIX: formatting in LogFormatterExponent
c6dda2d

@mdboom mdboom merged commit c6dda2d into matplotlib:master Dec 14, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.02%) to 67.496%
Details

mdboom removed the needs_review label Dec 14, 2015

@mdboom mdboom added a commit that referenced this pull request Dec 14, 2015

@mdboom mdboom Merge pull request #5594 from tacaswell/fix_logformatterexponent
FIX: formatting in LogFormatterExponent
7414cf0
Owner

mdboom commented Dec 14, 2015

Backported to 2.0.x as 7414cf0

tacaswell deleted the tacaswell:fix_logformatterexponent branch Dec 19, 2015

@tacaswell tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Dec 19, 2015

@mdboom @tacaswell mdboom + tacaswell Merge pull request #5594 from tacaswell/fix_logformatterexponent
FIX: formatting in LogFormatterExponent
5ff7e37
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