• <legend id='EjXmt'><style id='EjXmt'><dir id='EjXmt'><q id='EjXmt'></q></dir></style></legend>

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

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

        Python包将两个热图合二为一(将每个正方形分成两个三角形)

        Python package to plot two heatmaps in one (split each square into two triangles)(Python包将两个热图合二为一(将每个正方形分成两个三角形))
            <tbody id='wkBpR'></tbody>

          <tfoot id='wkBpR'></tfoot>

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

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

                <bdo id='wkBpR'></bdo><ul id='wkBpR'></ul>

                1. 本文介绍了Python包将两个热图合二为一(将每个正方形分成两个三角形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I've been searching around but couldn't find an easy solution to plot two heatmaps in one graphic by having each square in the heatmap split into two triangles (similar to the attached graphic I saw in a paper). Does anybody know a Python package that is able to do this? I tried seaborn but I don't think it has an easy way to achieve this.

                  Thank you for your time!

                  -Peter

                  解决方案

                  plt.tripcolor colors a mesh of triangles similar to how plt.pcolormesh colors a rectangular mesh. Also similar to pcolormesh, care has to be taken that there is one row and one column of vertices less than there are triangles. Furthermore, the arrays need to be made 1D (np.ravel). All this renumbering to 1D can be a bit tricky.

                  As an example, the code below creates a coloring depending on x*y mod 10 and uses two different colormaps for the upper and the lower triangles.

                  import numpy as np
                  import matplotlib.pyplot as plt
                  from matplotlib.tri import Triangulation
                  
                  M = 30
                  N = 20
                  x = np.arange(M + 1)
                  y = np.arange(N + 1)
                  xs, ys = np.meshgrid(x, y)
                  zs = (xs * ys) % 10
                  zs = zs[:-1, :-1].ravel()
                  
                  triangles1 = [(i + j*(M+1), i+1 + j*(M+1), i + (j+1)*(M+1)) for j in range(N) for i in range(M)]
                  triangles2 = [(i+1 + j*(M+1), i+1 + (j+1)*(M+1), i + (j+1)*(M+1)) for j in range(N) for i in range(M)]
                  triang1 = Triangulation(xs.ravel(), ys.ravel(), triangles1)
                  triang2 = Triangulation(xs.ravel(), ys.ravel(), triangles2)
                  img1 = plt.tripcolor(triang1, zs, cmap=plt.get_cmap('inferno', 10), vmax=10)
                  img2 = plt.tripcolor(triang2, zs, cmap=plt.get_cmap('viridis', 10), vmax=10)
                  
                  plt.colorbar(img2, ticks=range(10), pad=-0.05)
                  plt.colorbar(img1, ticks=range(10))
                  plt.xlim(x[0], x[-1])
                  plt.ylim(y[0], y[-1])
                  plt.xticks(x, rotation=90)
                  plt.yticks(y)
                  plt.show()
                  

                  PS: to have the integer ticks nicely in the center of the cells (instead of at their borders), following changes would be needed:

                  triang1 = Triangulation(xs.ravel()-0.5, ys.ravel()-0.5, triangles1)
                  triang2 = Triangulation(xs.ravel()-0.5, ys.ravel()-0.5, triangles2)
                  
                  # ...
                  plt.xlim(x[0]-0.5, x[-1]-0.5)
                  plt.ylim(y[0]-0.5, y[-1]-0.5)
                  plt.xticks(x[:-1], rotation=90)
                  plt.yticks(y[:-1]) 
                  

                  这篇关于Python包将两个热图合二为一(将每个正方形分成两个三角形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

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

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

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

                      • <tfoot id='IMVli'></tfoot>

                              <tbody id='IMVli'></tbody>