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

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

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

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

      1. <legend id='czmIn'><style id='czmIn'><dir id='czmIn'><q id='czmIn'></q></dir></style></legend>

        如何用 3 个数组做彩色 2D 网格

        How to do colored 2D grid with 3 arrays(如何用 3 个数组做彩色 2D 网格)
            <tbody id='LZoqn'></tbody>

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

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

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

                  <legend id='LZoqn'><style id='LZoqn'><dir id='LZoqn'><q id='LZoqn'></q></dir></style></legend>
                  本文介绍了如何用 3 个数组做彩色 2D 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有三个长度相等的数组 x、y 和 z.x 和 y 数组是网格的 x 轴和 y 轴.z 数组将确定网格块的颜色.例如,

                  x = [10, 10, 10, 20, 20, 20, 30, 30, 30]y = [10, 20, 30, 10, 20, 30, 10, 20, 30]z = [100, 54, 32, 67, 71, 88, 100, 15, 29]

                  像这样制作 3D 绘图很容易

                  ax.plot_trisurf(x, y, z, cmap=cm.RdYlGn)

                  ax.bar3d(x, y, [0] * len(x), 100, 100, z, cmap=cm.RdYlGn)

                  但我正在寻找类似的东西

                  I have three arrays of equal length x, y, and z. The x and y arrays are the x-axis and y-axis for the grid. The z array will determine the color of the the grid block. For example,

                  x = [10, 10, 10, 20, 20, 20, 30, 30, 30]
                  y = [10, 20, 30, 10, 20, 30, 10, 20, 30]
                  z = [100, 54, 32, 67, 71, 88, 100, 15, 29]
                  

                  It is easy to make 3D plots out of this like

                  ax.plot_trisurf(x, y, z, cmap=cm.RdYlGn)
                  

                  or

                  ax.bar3d(x, y, [0] * len(x), 100, 100, z, cmap=cm.RdYlGn)
                  

                  But I am looking for something like this

                  解决方案

                  np.meshgrid returns a tuple of two 2D arrays, which you can unpack directly

                  X,Y = np.meshgrid(x,y)
                  

                  However, you don't need to those for an imshow plot. What you need and what you lack in your code is the 2D array of z values. This would be the array to provide to imshow.

                  img = plt.imshow(Z)
                  

                  If you want to use meshgrid instead, you can use your X and Y values,

                  plt.pcolormesh(X,Y,Z)
                  

                  Seeing the example data, you can use imshow:

                  x = [10, 10, 10, 20, 20, 20, 30, 30, 30]
                  y = [10, 20, 30, 10, 20, 30, 10, 20, 30]
                  z = [100, 54, 32, 67, 71, 88, 100, 15, 29]
                  
                  import matplotlib.pyplot as plt
                  import numpy as np
                  
                  z = np.array(z).reshape(3,3)
                  
                  plt.imshow(z,extent=[5,35,5,35])
                  
                  plt.show()
                  

                  这篇关于如何用 3 个数组做彩色 2D 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                  <tfoot id='7QNzG'></tfoot>

                  <small id='7QNzG'></small><noframes id='7QNzG'>

                    <tbody id='7QNzG'></tbody>

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