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

        <tfoot id='fEpgP'></tfoot>
          <bdo id='fEpgP'></bdo><ul id='fEpgP'></ul>

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

      1. <legend id='fEpgP'><style id='fEpgP'><dir id='fEpgP'><q id='fEpgP'></q></dir></style></legend>
      2. 在 matplotlib 中映射六边形网格

        时间:2023-07-24

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

                <tfoot id='8hvie'></tfoot>

                <small id='8hvie'></small><noframes id='8hvie'>

                • <bdo id='8hvie'></bdo><ul id='8hvie'></ul>
                  本文介绍了在 matplotlib 中映射六边形网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想画一个带有六边形网格的图形.最终结果应该看起来像一个蜂窝.但是,我无法使用 matplotlib.collections.RegularPolyCollection 正确调整六边形的大小.谁能看到我做错了什么,或提供另一种解决方案.我想这已经完成了,所以我不需要重新发明轮子.

                  import matplotlib.pyplot as plt从 matplotlib 导入集合,转换从 matplotlib.colors 导入颜色转换器将 numpy 导入为 np# 做一些偏移,这里为了简单起见做 4 个多边形xyo = [(0,0), (1,0), (0,1), (1,1)]# 六边形边长六边形 = 1# 六边形外接圆的面积circ_area = np.pi * hexside ** 2无花果,斧头 = plt.subplots(1,1)col = collections.RegularPolyCollection(6, np.radians(90), sizes = (circ_area,),偏移量=xyo,transOffset=ax.transData)ax.add_collection(col, autolim=True)颜色 = [colorConverter.to_rgba(c) for c in ('r','g','b','c')]col.set_color(颜色)ax.autoscale_view()plt.show()

                  解决方案

                  谁在 2020+ 年遇到同样的问题,请查看我的

                  安装:

                  '>>点安装 hexalattice'

                  高级功能

                  该模块允许堆叠少量网格、围绕其中心任意旋转网格、对六边形之间的间隙进行高级控制等.

                  例子:

                  hex_grid1, h_ax = create_hex_grid(nx=50,ny=50,旋转度= 0,min_diam=1,crop_circ=20,do_plot=真)create_hex_grid(nx=50,ny=50,min_diam=1,旋转度=5,crop_circ=20,do_plot=真,h_ax=h_ax)

                  I'm wanting to draw a figure with a hexagonal grid. The end result should look like a honeycomb. However, I'm having trouble getting my hexagons sized correctly using matplotlib.collections.RegularPolyCollection. Can anyone see what I am doing wrong, or offer another solution. I imagine this has been done before, so no need for me to reinvent the wheel.

                  import matplotlib.pyplot as plt
                  from matplotlib import collections, transforms
                  from matplotlib.colors import colorConverter
                  import numpy as np
                  
                  # Make some offsets, doing 4 polygons for simplicity here
                  xyo = [(0,0), (1,0), (0,1), (1,1)]
                  # length of hexagon side
                  hexside = 1
                  # area of circle circumscribing the hexagon
                  circ_area = np.pi * hexside ** 2
                  
                  fig, ax = plt.subplots(1,1)
                  col = collections.RegularPolyCollection(6, np.radians(90), sizes = (circ_area,),
                      offsets=xyo,transOffset=ax.transData)
                  ax.add_collection(col, autolim=True)
                  colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c')]
                  col.set_color(colors)
                  ax.autoscale_view()
                  plt.show()
                  

                  解决方案

                  Whoever struggles with the same issue in 2020+, check out my hexalattice module: It allows to create hexagonal grids (hexagonal lattices) in 2D with fine control over spatial distribution of the hexagons, circular clop of the lattice and rotations around the central slot.

                  Usage and graphical output:

                  from hexalattice.hexalattice import *
                  hex_centers, _ = create_hex_grid(nx=10,
                                                   ny=10,
                                                   do_plot=True)
                  plt.show()    # import matplotlib.pyplot as plt
                  

                  Installation:

                  '>> pip install hexalattice'
                  

                  Advanced features

                  The module allows stacking of few grids, arbitrary grid rotation around its center, advanced control over gaps between the hexagons etc.

                  Example:

                  hex_grid1, h_ax = create_hex_grid(nx=50,
                                                ny=50,
                                                rotate_deg=0,
                                                min_diam=1,
                                                crop_circ=20,
                                                do_plot=True)
                  create_hex_grid(nx=50,
                                  ny=50,
                                  min_diam=1,
                                  rotate_deg=5,
                                  crop_circ=20,
                                  do_plot=True,
                                  h_ax=h_ax)
                  

                  这篇关于在 matplotlib 中映射六边形网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:远程执行任意 python 代码 - 可以吗? 下一篇:在网格中查找相邻单元格的 Pythonic 和有效方法

                  相关文章

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

                        <bdo id='fKtCt'></bdo><ul id='fKtCt'></ul>
                    3. <tfoot id='fKtCt'></tfoot>

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