display matrix values and colormap

后端 未结 2 1735
醉酒成梦
醉酒成梦 2021-02-04 07:31

I need to display values of my matrix using matshow. However, with the code I have now I just get two matrices - one with values and other colored. How do I impose them? Thanks

2条回答
  •  日久生厌
    2021-02-04 08:18

    In Jupyter notebooks this is also possible with DataFrames and Seaborn:

    import numpy as np
    import seaborn as sns
    import pandas as pd
    
    min_val, max_val = 0, 15
    intersection_matrix = np.random.randint(0, 10, size=(max_val, max_val))
    cm = sns.light_palette("blue", as_cmap=True)
    x=pd.DataFrame(intersection_matrix)
    x=x.style.background_gradient(cmap=cm)
    display(x)
    

提交回复
热议问题