display matrix values and colormap

后端 未结 2 746
生来不讨喜
生来不讨喜 2021-02-04 07:53

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:19

    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)
    

提交回复
热议问题