• <bdo id='QeSOx'></bdo><ul id='QeSOx'></ul>

  1. <small id='QeSOx'></small><noframes id='QeSOx'>

    <i id='QeSOx'><tr id='QeSOx'><dt id='QeSOx'><q id='QeSOx'><span id='QeSOx'><b id='QeSOx'><form id='QeSOx'><ins id='QeSOx'></ins><ul id='QeSOx'></ul><sub id='QeSOx'></sub></form><legend id='QeSOx'></legend><bdo id='QeSOx'><pre id='QeSOx'><center id='QeSOx'></center></pre></bdo></b><th id='QeSOx'></th></span></q></dt></tr></i><div id='QeSOx'><tfoot id='QeSOx'></tfoot><dl id='QeSOx'><fieldset id='QeSOx'></fieldset></dl></div>
    <tfoot id='QeSOx'></tfoot>
    <legend id='QeSOx'><style id='QeSOx'><dir id='QeSOx'><q id='QeSOx'></q></dir></style></legend>

      如何将Disrerte值映射到海运中的热图?

      How to map discrerte values to a heatmap in seaborn?(如何将Disrerte值映射到海运中的热图?)

        <bdo id='V0b5T'></bdo><ul id='V0b5T'></ul>
          <tbody id='V0b5T'></tbody>

        <tfoot id='V0b5T'></tfoot>

        <small id='V0b5T'></small><noframes id='V0b5T'>

        • <i id='V0b5T'><tr id='V0b5T'><dt id='V0b5T'><q id='V0b5T'><span id='V0b5T'><b id='V0b5T'><form id='V0b5T'><ins id='V0b5T'></ins><ul id='V0b5T'></ul><sub id='V0b5T'></sub></form><legend id='V0b5T'></legend><bdo id='V0b5T'><pre id='V0b5T'><center id='V0b5T'></center></pre></bdo></b><th id='V0b5T'></th></span></q></dt></tr></i><div id='V0b5T'><tfoot id='V0b5T'></tfoot><dl id='V0b5T'><fieldset id='V0b5T'></fieldset></dl></div>

            <legend id='V0b5T'><style id='V0b5T'><dir id='V0b5T'><q id='V0b5T'></q></dir></style></legend>

              1. 本文介绍了如何将Disrerte值映射到海运中的热图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用Seborn绘制热图中的离散值。以下是我试图绘制的列表:

                xa = [[5, 4, 4, 4, 13, 4, 4],
                 [1, 9, 4, 3, 9, 1, 4],
                 [4, 1, 7, 1, 5, 3, 7],
                 [1, 9, 4, 3, 9, 5, 4],
                 [2, 1, 4, 1, 9, 4, 3],
                 [9, 4, 8, 1, 7, 1, 9],
                 [4, 8, 1, 7, 1, 4, 8]]
                

                以下是我用来绘制热图的代码:

                import numpy as np
                import seaborn as sns
                from matplotlib.colors import ListedColormap
                data = np.asarray(xa)
                sns.heatmap( data,cmap=ListedColormap(['green', 'yellow', 'red']))
                

                我的问题是如何将每个数字绘制成特定的颜色。取值范围为1-17。所以有17种不同的颜色,每个数字一种。我读了一些其他的答案,但没有一个谈到如何给一个数字赋一个特定值。谢谢!

                推荐答案

                如果我理解正确,您可以这样做:

                import numpy as np
                from matplotlib import pyplot as plt
                import matplotlib.colors as c
                data = np.asarray(xa)
                colors = {"white":1, "gray":2, "yellow":3, "lightgreen":4, "green":5, "lightblue":6, "blue":7, "lightcoral":8, "red":9, "brown":10,
                          "violet":11, "blueviolet":12, "indigo":13, "khaki":14, "orange":15, "pink":16, "black":17}
                l_colors = sorted(colors, key=colors.get)
                cMap = c.ListedColormap(l_colors)
                fig, ax = plt.subplots()
                ax.pcolor(data[::-1], cmap=cMap, vmin=1, vmax=len(colors))
                # plt.axis('off') # if you don't want the axis
                plt.show()
                

                每个数字对应一种颜色,从1(白色)、2(灰色)到17(黑色)。如您所见,图像中没有黑色,因为您的数组中没有17,并且色彩映射表未标准化。

                seaborn

                data = np.asarray(xa)
                colors = {"white":1,"gray":2,"yellow":3,"lightgreen":4, "green":5, "lightblue":6, "blue":7, "lightcoral":8, "red":9, "brown":10,
                          "violet":11, "blueviolet":12,"indigo":13, "khaki":14, "orange":15, "pink":16, "black":17}
                l_colors = sorted(colors, key=colors.get)
                cMap = c.ListedColormap(l_colors)
                sns.heatmap(data,cmap=l_colors, vmin=1, vmax=len(colors))
                

                如果您想要图例上的所有刻度,请添加以下内容:

                ax = sns.heatmap(data,cmap=l_colors, vmin=1, vmax=len(colors))
                colorbar = ax.collections[0].colorbar
                colorbar.set_ticks([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])
                

                这篇关于如何将Disrerte值映射到海运中的热图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                <tfoot id='9vsyZ'></tfoot>

                  <small id='9vsyZ'></small><noframes id='9vsyZ'>

                    1. <i id='9vsyZ'><tr id='9vsyZ'><dt id='9vsyZ'><q id='9vsyZ'><span id='9vsyZ'><b id='9vsyZ'><form id='9vsyZ'><ins id='9vsyZ'></ins><ul id='9vsyZ'></ul><sub id='9vsyZ'></sub></form><legend id='9vsyZ'></legend><bdo id='9vsyZ'><pre id='9vsyZ'><center id='9vsyZ'></center></pre></bdo></b><th id='9vsyZ'></th></span></q></dt></tr></i><div id='9vsyZ'><tfoot id='9vsyZ'></tfoot><dl id='9vsyZ'><fieldset id='9vsyZ'></fieldset></dl></div>
                        <bdo id='9vsyZ'></bdo><ul id='9vsyZ'></ul>

                          <tbody id='9vsyZ'></tbody>

                          <legend id='9vsyZ'><style id='9vsyZ'><dir id='9vsyZ'><q id='9vsyZ'></q></dir></style></legend>