Home > front end >  Python Seaborn Heatmap - Numpy asarray()
Python Seaborn Heatmap - Numpy asarray()

Time:12-22

I'm trying to change the way the image (attached) looks on display. Instead of displaying the float, I am wanting to return a percentage, i.e. instead of 1.00 it would display 100%, -.15 would display as -15%, etc.

Below is the section of the code that creates a label. I've tried different things but no success so far. Any help or suggestions are great appreciated.

labels = (np.asarray(["{0} \n {1:2f}".format(symb,value)
                      for symb, value in zip(symbol.flatten(),
                                             perchange.flatten())])
          ).reshape(3,10)

If this isn't an easy task without some heavier code, how can I trim the number to two decimal places?

Output Example

CodePudding user response:

Try using .2f instead of just 2f:

labels = (np.asarray(["{0} \n {1:.2f}".format(symb,value)
                      for symb, value in zip(symbol.flatten(),
                                             perchange.flatten())])
          ).reshape(3,10)

  • Related