首页 > 解决方案 > matplotlib 中带有欧元符号的刻度

问题描述

我正在尝试绘制具有轴欧元单位之一的图。我正在格式化的功能是:

def money(x, pos):
    return '$%1.0fB' % (x*1e-9)

它适用于 $。现在我需要将 $ 与无法直接识别的 € 符号互换。

我尝试的是:

def money(x, pos):
    return r'$\euro$%1.0fB' % (x*1e-9)

但终端说:

Unknown symbol: \euro

标签: pythonmatplotlibformattingascii

解决方案


您还可以尝试使用\texteuroas

import matplotlib.pyplot as plt
from matplotlib import rc
rc('text', usetex=True)

plt.plot(range(5))
plt.xlabel(r'\texteuro%1.0fB')
plt.show()

在此处输入图像描述


推荐阅读