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

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

    2. <small id='P9KnX'></small><noframes id='P9KnX'>

      <tfoot id='P9KnX'></tfoot>

          <bdo id='P9KnX'></bdo><ul id='P9KnX'></ul>
      1. matplotlib:设置主要和次要刻度会强制使用相同的 x 和 y 比例

        matplotlib: Setting both major and minor ticks forces same x and y scale(matplotlib:设置主要和次要刻度会强制使用相同的 x 和 y 比例)
      2. <legend id='DDhqJ'><style id='DDhqJ'><dir id='DDhqJ'><q id='DDhqJ'></q></dir></style></legend>

      3. <tfoot id='DDhqJ'></tfoot>

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

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

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

                • 本文介绍了matplotlib:设置主要和次要刻度会强制使用相同的 x 和 y 比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这个问题与我之前提出的问题matplotlib:更改网格间隔并指定刻度标签"但现在我想更改 x 和 y 轴的比例.当我设置 x 和 y 轴的范围,然后指定主要和次要刻度的间隔时,它会强制 x 和 y 轴相同.

                  This question is related to the earlier question I asked "matplotlib: Change grid interval and specify tick labels" but now I want to change the scale for x and y axes. When I set the range for x and y axes and then specify the intervals for major and minor ticks, it forces the x and y axes to be the same.

                  这是我的代码.

                  import matplotlib.pyplot as plt
                  import numpy as np
                  
                  fig = plt.figure()
                  ax = fig.add_subplot(111)
                  
                  for key, value in sorted(data.items()):
                      x = value[0][2]
                      y = value[0][3]
                      count = value[0][4]
                  
                      ax.annotate(count, xy = (x, y), size = 3)
                  
                  plt.suptitle('Number of counts', fontsize = 12)
                  
                  ax.set_xlabel('x')
                  ax.set_ylabel('y')
                  ax.set_aspect('equal')
                  
                  # I want max x axis to be 500
                  ax.set_xlim(0, 501)
                  # I want max y axis to be 300
                  ax.set_ylim(0, 301)
                  
                  # I want major ticks to be every 20
                  major_ticks = np.arange(0, 501, 20)
                  
                  # I want minor ticks to be every 5
                  minor_ticks = np.arange(0, 501, 5)
                  # If I do minor_ticks = np.arange(0, 301, 5), I will not get minor ticks for the entire plot
                  
                  # Specify tick label size
                  ax.tick_params(axis = 'both', which = 'major', labelsize = 4)
                  ax.tick_params(axis = 'both', which = 'minor', labelsize = 0)
                  # Suppress minor tick labels
                  
                  ax.set_xticks(major_ticks)
                  ax.set_xticks(minor_ticks, minor = True)
                  ax.set_yticks(major_ticks)
                  ax.set_yticks(minor_ticks, minor = True)
                  
                  # Set both ticks to be outside
                  ax.tick_params(which = 'both', direction = 'out')
                  
                  # Specify different settings for major and minor grids
                  ax.grid(which = 'minor', alpha = 0.3)
                  ax.grid(which = 'major', alpha = 0.7)
                  
                  filename = 'C:UsersOwlDesktopPlot.png'
                  plt.savefig(filename, dpi = 150)
                  plt.close()
                  

                  这就是我得到的.

                  我怎样才能得到 x 和 y 轴的不同范围并且仍然有这样的主要和次要刻度?我可能遗漏了一些非常简单的东西,但如果有人能指出,我非常感谢!

                  How could I get different ranges for x and y axes and still have major and minor ticks like this? I might be missing something very simple but if somebody could point it out, I am very thankful for that!!

                  推荐答案

                  那是因为您将 x 和 y 刻度设置为相同的东西.如果您想要不同的尺寸,那么您还需要不同的刻度.您不能将两组刻度设置为相同的 major_ticks 位置.为 x 轴制作一个刻度位置列表,为 y 轴制作一个单独的刻度位置列表,然后将每个轴的刻度设置到相应的列表中.

                  That's because you set the x and y ticks to the same thing. If you want different sizes, then you also need different ticks. You can't set both sets of ticks to the same major_ticks positions. Make one list of tick positions for the x axis and a separate list of tick positions for y axis and then set the ticks for each axis to the corresponding list.

                  这篇关于matplotlib:设置主要和次要刻度会强制使用相同的 x 和 y 比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 画布滚动条?)
                • <small id='1Viyt'></small><noframes id='1Viyt'>

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

                    • <tfoot id='1Viyt'></tfoot>
                            <bdo id='1Viyt'></bdo><ul id='1Viyt'></ul>
                            <legend id='1Viyt'><style id='1Viyt'><dir id='1Viyt'><q id='1Viyt'></q></dir></style></legend>