<bdo id='6rXHq'></bdo><ul id='6rXHq'></ul>
      <tfoot id='6rXHq'></tfoot>

      <small id='6rXHq'></small><noframes id='6rXHq'>

        <i id='6rXHq'><tr id='6rXHq'><dt id='6rXHq'><q id='6rXHq'><span id='6rXHq'><b id='6rXHq'><form id='6rXHq'><ins id='6rXHq'></ins><ul id='6rXHq'></ul><sub id='6rXHq'></sub></form><legend id='6rXHq'></legend><bdo id='6rXHq'><pre id='6rXHq'><center id='6rXHq'></center></pre></bdo></b><th id='6rXHq'></th></span></q></dt></tr></i><div id='6rXHq'><tfoot id='6rXHq'></tfoot><dl id='6rXHq'><fieldset id='6rXHq'></fieldset></dl></div>
        <legend id='6rXHq'><style id='6rXHq'><dir id='6rXHq'><q id='6rXHq'></q></dir></style></legend>
      1. 改变“滴答频率"在 matplotlib 的 x 或 y 轴上

        Changing the quot;tick frequencyquot; on x or y axis in matplotlib(改变“滴答频率在 matplotlib 的 x 或 y 轴上)

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

              <legend id='ED41T'><style id='ED41T'><dir id='ED41T'><q id='ED41T'></q></dir></style></legend>
                <tbody id='ED41T'></tbody>

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

                • <i id='ED41T'><tr id='ED41T'><dt id='ED41T'><q id='ED41T'><span id='ED41T'><b id='ED41T'><form id='ED41T'><ins id='ED41T'></ins><ul id='ED41T'></ul><sub id='ED41T'></sub></form><legend id='ED41T'></legend><bdo id='ED41T'><pre id='ED41T'><center id='ED41T'></center></pre></bdo></b><th id='ED41T'></th></span></q></dt></tr></i><div id='ED41T'><tfoot id='ED41T'></tfoot><dl id='ED41T'><fieldset id='ED41T'></fieldset></dl></div>
                • <tfoot id='ED41T'></tfoot>
                  本文介绍了改变“滴答频率"在 matplotlib 的 x 或 y 轴上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试修复 python 如何绘制我的数据.

                  I am trying to fix how python plots my data.

                  x = [0,5,9,10,15]
                  

                  y = [0,1,2,3,4]
                  

                  那么我会这样做:

                  matplotlib.pyplot.plot(x,y)
                  matplotlib.pyplot.show()
                  

                  并且 x 轴的刻度以 5 的间隔绘制.有没有办法让它显示 1 的间隔?

                  and the x axis' ticks are plotted in intervals of 5. Is there a way to make it show intervals of 1?

                  推荐答案

                  您可以使用 plt.xticks 显式设置要标记的位置:

                  You could explicitly set where you want to tick marks with plt.xticks:

                  plt.xticks(np.arange(min(x), max(x)+1, 1.0))
                  

                  <小时>

                  例如,

                  import numpy as np
                  import matplotlib.pyplot as plt
                  
                  x = [0,5,9,10,15]
                  y = [0,1,2,3,4]
                  plt.plot(x,y)
                  plt.xticks(np.arange(min(x), max(x)+1, 1.0))
                  plt.show()
                  

                  <小时>使用

                  (np.arange 而不是 Python 的 range 函数,以防 min(x)max(x) 是浮点数而不是整数.)


                  (np.arange was used rather than Python's range function just in case min(x) and max(x) are floats instead of ints.)

                  plt.plot(或ax.plot)函数将自动设置默认xy限制.如果您希望保持这些限制,并且只是更改刻度线的步长,那么您可以使用 ax.get_xlim() 来发现 Matplotlib 已经设置的限制.

                  The plt.plot (or ax.plot) function will automatically set default x and y limits. If you wish to keep those limits, and just change the stepsize of the tick marks, then you could use ax.get_xlim() to discover what limits Matplotlib has already set.

                  start, end = ax.get_xlim()
                  ax.xaxis.set_ticks(np.arange(start, end, stepsize))
                  

                  默认的刻度格式化程序应该可以将刻度值四舍五入到合理的有效数字位数.但是,如果您希望对格式有更多的控制,您可以定义自己的格式化程序.例如,

                  The default tick formatter should do a decent job rounding the tick values to a sensible number of significant digits. However, if you wish to have more control over the format, you can define your own formatter. For example,

                  ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))
                  

                  这是一个可运行的示例:

                  Here's a runnable example:

                  import numpy as np
                  import matplotlib.pyplot as plt
                  import matplotlib.ticker as ticker
                  
                  x = [0,5,9,10,15]
                  y = [0,1,2,3,4]
                  fig, ax = plt.subplots()
                  ax.plot(x,y)
                  start, end = ax.get_xlim()
                  ax.xaxis.set_ticks(np.arange(start, end, 0.712123))
                  ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))
                  plt.show()
                  

                  这篇关于改变“滴答频率"在 matplotlib 的 x 或 y 轴上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                  <tfoot id='V7AJR'></tfoot>
                  <legend id='V7AJR'><style id='V7AJR'><dir id='V7AJR'><q id='V7AJR'></q></dir></style></legend>

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

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

                            <bdo id='V7AJR'></bdo><ul id='V7AJR'></ul>
                              <tbody id='V7AJR'></tbody>