【问题标题】:x-axis spacing with log base 2 scale + rendering angstrom unit on the x-axisx 轴间距,对数基数为 2 比例 + 在 x 轴上渲染埃单位
【发布时间】:2022-06-28 22:23:53
【问题描述】:

我有一个简单的数据集,我需要它的 x 轴值在对数基数 2 上。此外,我曾经像在 LaTeX 中那样输入 \Delta \angstrom 或任何数学表达式,然后打印出单位,这次它似乎对我不起作用。知道为什么吗?

我的代码:

import matplotlib.pyplot as plt
    

x = [0.35,0.38,0.47,0.53,0.6,0.7,0.84,1.53]

y = [0,0.36,0.87,2.84,7.58,11.25,14.33,19.64]
    

plt.plot(x, y)
    

plt.xlabel(r'Grid spacing [\angstrom]')

plt.ylabel(r'% error')


plt.title('x-y plot')
    

plt.show()

【问题讨论】:

    标签: matplotlib logging


    【解决方案1】:

    试试这个:

    import matplotlib.pyplot as plt
    x = [0.35,0.38,0.47,0.53,0.6,0.7,0.84,1.53]
    y = [0,0.36,0.87,2.84,7.58,11.25,14.33,19.64]
    
    plt.plot(x, y)
    plt.xlabel(r'Grid spacing $\Delta\AA$')
    plt.ylabel(r'% error')
    plt.title('x-y plot')
    plt.xscale('log', base=2)
    plt.show()
    

    我将base 提供给xscale 函数以指定base-2 日志,并将您对\angstrom 的用法更改为\AA。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多