简体   繁体   English

如何在 plotly express (px.imshow) 的热图中不显示重复值?

[英]How to not show repeated values in a heatmap in plotly express (px.imshow)?

I'm trying to plot a matrix using a heatmap chart but I would like to avoid repeated values;我正在尝试使用热图 plot 矩阵,但我想避免重复值;

When using seaborn we can set a "mask" to avoid showing all values, but I can't find the equivalent on Plotly / Plotly Express;使用 seaborn 时,我们可以设置一个“掩码”以避免显示所有值,但我在 Plotly / Plotly Express 上找不到等效项;

I would like to see something like:我想看到类似的东西: 在此处输入图像描述

But at this moment, it is the below format:但是此时,它是以下格式:

在此处输入图像描述

Below is an MWE example of my data structure... Any reference or help to do this will be very welcome下面是我的数据结构的 MWE 示例......非常欢迎任何参考或帮助这样做

import pandas as pd
import plotly.express as px

heatmap_data=pd.DataFrame(
    {'user1': {'user1': 1,
               'user2': 0.5267109866774764,
               'user3': 0.905914413030722},
    'user2': {'user1': 0.5267109866774764,
              'user2': 1,
              'user3': 0.5160264783692895},
    'user3': {'user1': 0.905914413030722,
              'user2': 0.5160264783692895,
              'user3': 1}
    })
fig = px.imshow(heatmap_data,  zmin=0, zmax=1, 
                text_auto=True, 
                color_continuous_scale="Plasma")
fig

Thank you in advantage谢谢你的好处

The plotly heatmap does not implement the functionality you would expect. plotly 热图未实现您期望的功能。 Also, matrix diagrams such as scatter plots have the ability to hide the top half.此外,散点图等矩阵图具有隐藏上半部分的能力。 See this for examples .请参阅此示例 So I take advantage of the fact that null values are not displayed and replace unwanted data with null values in the original data.因此,我利用未显示 null 值这一事实,将原始数据中不需要的数据替换为 null 值。 The default style then remains, so we change the theme and hide the axis lines.然后保留默认样式,因此我们更改主题并隐藏轴线。 Finally, the height of the color bar is adjusted.最后,调整颜色条的高度。

import pandas as pd
import plotly.express as px

heatmap_data=pd.DataFrame(
    {'user1': {'user1': 1,
               'user2': 0.5267109866774764,
               'user3': 0.905914413030722},
    'user2': {'user1': 0.5267109866774764,
              'user2': 1,
              'user3': 0.5160264783692895},
    'user3': {'user1': 0.905914413030722,
              'user2': 0.5160264783692895,
              'user3': 1}
    })

heatmap_data.loc['user1','user2']=None
heatmap_data.loc['user1','user3']=None
heatmap_data.loc['user2','user3']=None

fig = px.imshow(heatmap_data,
                zmin=0,
                zmax=1,
                text_auto=True, 
                color_continuous_scale="Plasma",
                template='simple_white'
               )
fig.update_xaxes(showline=False)
fig.update_yaxes(showline=False)
fig.update_layout(autosize=False, width=400, coloraxis=dict(colorbar=dict(len=0.8)))
fig

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 plotly imshow / heatmap 的最后一行和最后一列中删除色标 - Remove colorscale from last row and column of a plotly imshow / heatmap 仅显示此热图的对角线值 - show just the diagonal values of this heatmap R中的热图矩阵如何重新排序? 如何以相同的方式用值对实际矩阵重新排序,使其对应于热图? - How is the matrix reordered for a heatmap in R? How to reorder the actual matrix with values in the same way so it corresponds to the heatmap? 带有数值的字典的热图 - Heatmap of a dictionary of dictionaries with numerical values 用其他颜色显示R热图异常值 - Show R heatmap outliers in a different colour 如何在矩阵中找到重复的值以及它们属于哪些行? - How to find the repeated values in a matrix and which rows they belong to? Python:如何计算在熊猫数据框中重复的对数值的数量? - Python: how to count number of couple values repeated in a pandas dataframe? 将数据推回Matrix并使用imshow显示该矩阵 - Push back Data into Matrix and show that matrix using imshow Python:如何将plt.imshow()嵌套在For循环中? - Python: How to nest plt.imshow() in a For loop? 如果一行在列的其他地方有重复值,如何取该行的最大值并返回一个新矩阵? - How to take the maximum value of a row if it has repeated values elsewhere in the column and return a new matrix?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM