【问题标题】:How to change point to comma in matplotlib graphics?如何在 matplotlib 图形中将点更改为逗号?
【发布时间】:2016-06-26 01:57:40
【问题描述】:

我想在使用this codethat code 的代码后将yticklabel 小数点分隔符从小数点更改为逗号,但保留偏移文本的格式 (1e-14)。

我的问题:

  1. 如何将点改为逗号并保存 1e-14?
  2. 如何将偏移文本中的e 更改为E

我正在使用 Python 3.5

【问题讨论】:

    标签: python python-3.x numpy matplotlib comma


    【解决方案1】:

    要将小数点分隔符从点更改为逗号,您可以将locale 更改为使用逗号的位置。例如,这里我设置为德语:

    #Locale settings
    import locale
    # Set to German locale to get comma decimal separater
    locale.setlocale(locale.LC_NUMERIC, "de_DE")
    
    import numpy as np
    import matplotlib.pyplot as plt
    plt.rcdefaults()
    
    # Tell matplotlib to use the locale we set above
    plt.rcParams['axes.formatter.use_locale'] = True
    
    # make the figure and axes
    fig,ax = plt.subplots(1)
    
    # Some example data
    x=np.arange(100)
    y=4e-18*x**2
    
    # plot the data
    ax.plot(x,y,'b-')
    
    plt.show()
    

    将偏移文本中的指数更改为E 似乎不是一项简单的任务。你可以先看看答案here

    【讨论】:

    • 我需要提供不同格式的语言环境:locale.setlocale(locale.LC_NUMERIC, ('pl_PL', 'UTF-8'))。我想知道您的回复中是否不应该是('de_DE', 'UTF-8') 'de_DE.UTF-8'(也许它取决于操作系统?)。
    • @matandked 对我来说也一样。 'de_DE.UTF-8' 适用于 Windows。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-27
    相关资源
    最近更新 更多