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

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

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

        使用 matplotlib 制作 2D 像素图

        时间:2023-07-24
          <tbody id='5J8qL'></tbody>

          • <bdo id='5J8qL'></bdo><ul id='5J8qL'></ul>

            <small id='5J8qL'></small><noframes id='5J8qL'>

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

              <legend id='5J8qL'><style id='5J8qL'><dir id='5J8qL'><q id='5J8qL'></q></dir></style></legend>

                  本文介绍了使用 matplotlib 制作 2D 像素图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我从一些计算中得到了以下数据:

                  I got the following data from some calculations:

                  x, y, temp
                  

                  其中 x 和 y 是尺寸为 10x10 的 2D 盒子中的点的坐标.间距等于 0.1.所以有 10000 个不同的点,生成的文件如下所示:

                  where x and y are the coordinates of a point in a 2D box of dimensions 10x10. Spacing is equal to 0.1. So there are 10000 different points and the resulting file looks like:

                  0.0 0.0 5.6
                  0.1 0.0 3.2
                  0.2 0.0 4.1
                  ...
                  9.9 9.9 2.1
                  

                  我想用 matplotlib 准备一种 2D 图,像素为 100x100,其中每个像素都有一种颜色(彩虹色从红色到紫色,从第三列的最小值到最大值)第三列的值,并从此文件中读取数据.我想知道使用 matplotlib 的最佳方法是什么

                  I would like to prepare kind of a 2D plot with matplotlib, with 100x100 pixels, where each pixel gets a colour (rainbow colors going from red to violet, from the minimum to the maximum values of the third column) according to the value of the 3rd column, and data is read from this file. I wonder what is the best approach for this with matplotlib

                  推荐答案

                  根据 x,y,temp 三元组的排序方式(按行列出),您可以重塑temp"列.

                  Based on the way it looks like your x,y,temp triples are ordered (listed out in rows), you can just reshape the "temp" column.

                  例如

                  import numpy as np
                  import matplotlib.pyplot as plt
                  import matplotlib.cm as cm
                  
                  x,y,temp = np.loadtxt('data.txt').T #Transposed for easier unpacking
                  nrows, ncols = 100, 100
                  grid = temp.reshape((nrows, ncols))
                  
                  plt.imshow(grid, extent=(x.min(), x.max(), y.max(), y.min()),
                             interpolation='nearest', cmap=cm.gist_rainbow)
                  plt.show()
                  

                  hsv 是您所指的彩虹"颜色图. 您可能实际上想要 matplotlib.cm.gist_rainbow.matplotlib.cm.hsv 在底部变回红色.请参阅此处:https://matplotlib.org/users/colormaps.html 获取颜色图列表.

                  hsv is the "rainbow" colormap you were referring to. You probably actually wanted matplotlib.cm.gist_rainbow. matplotlib.cm.hsv goes back to red at the bottom. See here: https://matplotlib.org/users/colormaps.html for a list of colormaps.

                  如果您的 x,y,temp 三元组实际上没有被排序,那么您需要重新计算您的分数.我在我的回答中展示了一个例子.

                  If your x,y,temp triplets aren't actually ordered, then you'll need to regrid your points. I showed an example of this in my answer to your previous question.

                  这篇关于使用 matplotlib 制作 2D 像素图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 tkinter 中创建一个自调整大小的按钮网格? 下一篇:带有网格的 tkinter 画布滚动条?

                  相关文章

                • <small id='Dibwb'></small><noframes id='Dibwb'>

                  <legend id='Dibwb'><style id='Dibwb'><dir id='Dibwb'><q id='Dibwb'></q></dir></style></legend>
                  <tfoot id='Dibwb'></tfoot>

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

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