I am trying to set the x-axis label to something with a prefix of micro so I want to insert the unicode ‘μ’ as it looks better to me with DejaVu Sans than using the tex-renderer.
In my example below I write 2 strings with the μ character in it.
The first string uses the mathtext font, which is by default DejaVu Sans.
The second uses the regular font, which I’ve tried to set to DejaVu Sans but it doesn’t seem to work.
The text renders fine in jupyter lab, however when I save it to a .pdf the default font doesn’t have the unicode symbol μ, so it fails. A push in the right direction would be greatly appreciated!
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['DejaVu Sans'] plt.rcParams['font.family'] = 'sans-serif' fig = plt.figure() ax = fig.gca() plt.text(0.5, 0.5, '$t = 1$ μs', transform = ax.transAxes, ha='center', va='center', fontsize=14) ax.set_xlabel('Time (μs)') plt.savefig('example.pdf')
The saved pdf looks like this: