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

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

      <tfoot id='zriIl'></tfoot>

      1. <legend id='zriIl'><style id='zriIl'><dir id='zriIl'><q id='zriIl'></q></dir></style></legend>
          <bdo id='zriIl'></bdo><ul id='zriIl'></ul>

        Matplotlib 对数刻度刻度标签,乳胶字体中的减号太长

        时间:2023-10-18

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

                <tbody id='Bzxqb'></tbody>
              1. <legend id='Bzxqb'><style id='Bzxqb'><dir id='Bzxqb'><q id='Bzxqb'></q></dir></style></legend>
                • <small id='Bzxqb'></small><noframes id='Bzxqb'>

                  本文介绍了Matplotlib 对数刻度刻度标签,乳胶字体中的减号太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 matplotib 中使用 'text.usetex': True.这对于具有线性比例的绘图非常有用.然而,对于对数刻度,y 刻度如下所示:

                  I'm using 'text.usetex': True in matplotib. This is nice for plots with a linear scale. For a log-scale however, the y-ticks looks like this:

                  指数中的减号在图中占用了大量的水平空间,这不是很好.我希望它看起来像这样:

                  The minus signs in the exponents take a lot of horizontal space in a plot, which is not very nice. I want it to rather look like that:

                  那个来自gnuplot,它没有使用tex-font.我想使用 matplotlib,让它在 tex 中渲染,但 10^{-n} 中的减号应该更短.这可能吗?

                  That one is from gnuplot, and it's not using the tex-font. I would like to use matplotlib, have it rendered in tex, but the minus signs in 10^{-n} should be shorter. Is that possible?

                  推荐答案

                  Dietrich 给了你一个很好的答案,但是如果你想保留所有的功能(非基数 10,非整数指数) 的 LogFormatter,那么您可以创建自己的格式化程序:

                  Dietrich gave you a nice answer, but if you want to keep all the functionality (non-base 10, non-integer exponents) of LogFormatter, then you might create your own formatter:

                  import matplotlib.ticker
                  import matplotlib
                  import re
                  
                  # create a definition for the short hyphen
                  matplotlib.rcParams["text.latex.preamble"].append(r'mathchardefmhyphen="2D')
                  
                  class MyLogFormatter(matplotlib.ticker.LogFormatterMathtext):
                      def __call__(self, x, pos=None):
                          # call the original LogFormatter
                          rv = matplotlib.ticker.LogFormatterMathtext.__call__(self, x, pos)
                  
                          # check if we really use TeX
                          if matplotlib.rcParams["text.usetex"]:
                              # if we have the string ^{- there is a negative exponent
                              # where the minus sign is replaced by the short hyphen
                              rv = re.sub(r'^{-', r'^{mhyphen', rv)
                  
                          return rv
                  

                  这真正做的唯一一件事就是获取通常格式化程序的输出,找到可能的负指数并将数学减号的 LaTeX 代码更改为其他内容.当然,如果你用 scalebox 或类似的东西发明了一些有创意的 LaTex,你可以这样做.

                  The only thing this really does is to grab the output of the usual formatter, find the possible negative exponents and change the LaTeX code of the math minus into something else. Of course, if you invent some creative LaTex with scalebox or something equivalent, you may do so.

                  这个:

                  import matplotlib.pyplot as plt
                  import numpy as np
                  
                  matplotlib.rcParams["text.usetex"] = True
                  fig = plt.figure()
                  ax = fig.add_subplot(111)
                  ax.semilogy(np.linspace(0,5,200), np.exp(np.linspace(-2,3,200)*np.log(10)))
                  ax.yaxis.set_major_formatter(MyLogFormatter())
                  fig.savefig("/tmp/shorthyphen.png")
                  

                  创建:

                  这个解决方案的好处是它尽可能少地改变输出.

                  The good thing about this solution is that it changes the output as minimally as possible.

                  这篇关于Matplotlib 对数刻度刻度标签,乳胶字体中的减号太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:SymPy 仅打印函数名称 下一篇:带有乳胶的轴刻度标签的无衬线字体

                  相关文章

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

                • <legend id='FJRzo'><style id='FJRzo'><dir id='FJRzo'><q id='FJRzo'></q></dir></style></legend>

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

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

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