• <legend id='1EuLQ'><style id='1EuLQ'><dir id='1EuLQ'><q id='1EuLQ'></q></dir></style></legend>

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

        <small id='1EuLQ'></small><noframes id='1EuLQ'>

          <bdo id='1EuLQ'></bdo><ul id='1EuLQ'></ul>
      2. matplotlib 图例标签与 LaTeX 数学的垂直对齐

        时间:2023-10-18
        <legend id='5cO2Z'><style id='5cO2Z'><dir id='5cO2Z'><q id='5cO2Z'></q></dir></style></legend><tfoot id='5cO2Z'></tfoot>
          <bdo id='5cO2Z'></bdo><ul id='5cO2Z'></ul>

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

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

                1. 本文介绍了matplotlib 图例标签与 LaTeX 数学的垂直对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  将带有下标的标签与不带下标的标签混合在一起时,它们在图例中无法正确垂直对齐.由于 matplotlib 根据打印字符在内部确定边界框,因此使用 vphantom 字符无法对齐这些图例标签,并且我没有任何运气使用 set_va 更改标签的垂直对齐方式,要么.

                  When mixing labels that have subscripts with labels without them, they do not vertically align properly in the legend. Since matplotlib determines bounding boxes internally based on printing characters, using a vphantom character does not work to align these legend labels, and I have not had any luck changing the vertical alignment of the labels with set_va, either.

                  下面是一个 MWE,它说明了我要解决的问题.如果可能的话,我希望标签与文本基线对齐,否则与文本顶部对齐.

                  Below is a MWE that illustrates problem I am trying to solve. I would like the labels to align to the text baseline if at all possible, otherwise to the text top.

                  import numpy as np
                  import matplotlib as mpl
                  mpl.rcParams['text.usetex'] = True
                  import matplotlib.pyplot as plt
                  
                  x = np.arange(10)
                  plt.plot(x, np.random.uniform(size=(10,)), c='red', label=r'test')
                  plt.scatter(x, np.random.uniform(size=(10,)), c='blue', label=r'test${}_{xy}$')
                  plt.legend(ncol=2)                                                                          
                  plt.show()
                  

                  推荐答案

                  text.latex.preview 参数设置为 True:

                  import numpy as np
                  import matplotlib as mpl
                  mpl.rcParams['text.usetex'] = True
                  mpl.rcParams['text.latex.preview'] = True
                  import matplotlib.pyplot as plt
                  
                  x = np.arange(10)
                  plt.plot(x, np.random.uniform(size=(10,)), c='red', label=r'test')
                  plt.scatter(x, np.random.uniform(size=(10,)), c='blue', label=r'test${}_{xy}$')
                  plt.legend(ncol=2)                                                      
                  
                  plt.show()
                  

                  preview参数的效果,另请参考这个例子.

                  For the effect of the preview argument, also refer to this example.

                  这篇关于matplotlib 图例标签与 LaTeX 数学的垂直对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 python 脚本编译 Latex 文件 下一篇:statsmodels汇总到乳胶

                  相关文章

                  <tfoot id='JBCu4'></tfoot>

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

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

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

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