79249679

Date: 2024-12-04 02:01:48
Score: 1
Natty:
Report link

Well, given James's answer, I came up with a workaround for my needs...Unicode!


    import holoviews as hv
    
    # create a dictionary to convert numbers to superscripts
    super_dict = {1:'\u00b1',
                  2:'\u00b2',
                  3:'\u00b2',
                  4:'\u2074',
                  5:'\u2075',
                  6:'\u2076',
                  7:'\u2077',
                  8:'\u2078',
                  9:'\u2079',
                  0:'\u2070'}
    
    # use some math to find the closest power of 10 that is below your
    # desired max. In my case, I wanted 10 rather than 1. One could also
    # probably modify this use %3 to cut off at some reasonable thousand
    def simplify_data(data, col):
        import math
        import numpy as np
        logscale = math.floor(np.log10(data[col].max()))
        new_data = data[col]/(10**(logscale-1))
        new_label = f'{col}/10{super_dict[logscale-1]}'
        data.loc[:, [new_label]] = new_data
        return data, new_label
    
    # create synthetic data
    x = np.linspace(start=0, stop=200000, num=25)
    y = np.linspace(start=0, stop=35, num=25)
    df_test = pd.DataFrame({'x':x, 'y': y})

    # run my new function to generate my scaled variable
    df_test, new_col = simplify_data(df_test, 'x')
    hv.Points(df_test, [new_col, 'y'])
    # the .opts(xlabel=...) is now not needed either

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Bradley Sutliff