如何在 MATLAB 中将图形打印为带有嵌入希腊字母或公式的 pdf 文件?
How can I print a figure to a pdf file with embedded greek letters or formulas in MATLAB?
我找不到使用打印功能(或 Yair Altman 的文件交换功能 export_fig())打印带有嵌入希腊字母的图形的解决方案。
虽然此功能在早期的 matlab 版本(例如 R2016a)中可用,但以下代码在 R2018a 版本中无法产生预期的结果:
figure()
rng = 0:0.01:2;
plot(rng, sin(rng.*pi()))
text(1, 0.6, 'sin of {\alpha}')
print('simple_test_p', '-dpdf')
% export_fig('simple_test_e','-pdf', '-transparent')
虽然“{\alpha}”之前的文本嵌入到生成的 pdf 文件中,但 alpha 本身似乎是图像而不是嵌入的字体(见图)。
我尝试了几种不同的字体来排除默认字体丢失的可能性(除了仔细检查字体文件夹)。此外,我同时使用了 latex 和 tex 解释器。然而,none 这些程序奏效了。
如果这个问题用Matlab解决不了,有没有其他方法可以得到一个嵌入了希腊字母和数学公式的pdf文件?
非常感谢你的帮助。提前谢谢你。
MATLAB 在所有地方都使用 Unicode 文本。你应该能够简单地做到:
text(1, 0.6, 'sin of ')
如果您不会输入希腊字母,您可以随时在 Google* 上搜索并复制粘贴。我找到了上面的 here.
*或任何您喜欢的搜索引擎。
或者只使用 matplotlib,它与 unicode 相处得很好:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10000)
y = np.sin(np.pi * x * 0.001)
plt.plot(x, y)
plt.ylabel(u"\u03B1")
plt.xlabel('β')
plt.savefig(r'<insert your path here>/sinewave.pdf')
plt.show()
我找不到使用打印功能(或 Yair Altman 的文件交换功能 export_fig())打印带有嵌入希腊字母的图形的解决方案。
虽然此功能在早期的 matlab 版本(例如 R2016a)中可用,但以下代码在 R2018a 版本中无法产生预期的结果:
figure()
rng = 0:0.01:2;
plot(rng, sin(rng.*pi()))
text(1, 0.6, 'sin of {\alpha}')
print('simple_test_p', '-dpdf')
% export_fig('simple_test_e','-pdf', '-transparent')
虽然“{\alpha}”之前的文本嵌入到生成的 pdf 文件中,但 alpha 本身似乎是图像而不是嵌入的字体(见图)。
我尝试了几种不同的字体来排除默认字体丢失的可能性(除了仔细检查字体文件夹)。此外,我同时使用了 latex 和 tex 解释器。然而,none 这些程序奏效了。
如果这个问题用Matlab解决不了,有没有其他方法可以得到一个嵌入了希腊字母和数学公式的pdf文件?
非常感谢你的帮助。提前谢谢你。
MATLAB 在所有地方都使用 Unicode 文本。你应该能够简单地做到:
text(1, 0.6, 'sin of ')
如果您不会输入希腊字母,您可以随时在 Google* 上搜索并复制粘贴。我找到了上面的 here.
*或任何您喜欢的搜索引擎。
或者只使用 matplotlib,它与 unicode 相处得很好:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10000)
y = np.sin(np.pi * x * 0.001)
plt.plot(x, y)
plt.ylabel(u"\u03B1")
plt.xlabel('β')
plt.savefig(r'<insert your path here>/sinewave.pdf')
plt.show()