Issue
I got a new computer and installed the latest version of anaconda a few days ago and am trying to use the same code as I had before which works on my other computer to plot. When I plot, it is unable to display the minus sign using the CMU Sans Serif font. It spits out the following error
C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 8722 missing from current font.
font.set_text(s, 0.0, flags=flags)
C:\Users\xxx\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 8722 missing from current font.
font.set_text(s, 0, flags=flags)
It also plots the following erroneous figure. Please refer to the negative sign of the color bar.
The following is my code:
plt.rcParams['font.sans-serif'] = "CMU Sans Serif"
plt.rcParams['font.family'] = "sans-serif"
plt.rcParams['mathtext.fontset'] = 'cm'
# I can provide any x,y,z data here and every negative data reproduces the same error
plt.scatter(x,y,c=z,cmap='jet')
plt.colorbar()
If I do not include the plt.rcParams['font.sans-serif'] = "CMU Sans Serif"
part it displays the negative sign correctly, however it is not the font I need at the moment. I checked by going to a Word Document and typing a negative sign with any of these fonts and they are all working properly, so it doesn't seem to be an issue with the font installation itself. Any help or direction on solving this issue would be greatly appreciated. Thanks in advance for any help or recommendations.
Solution
I found that by using
matplotlib.rcParams['axes.unicode_minus'] = False
I can fix this problem in that particular code.
If you want to fix this problem permanently, set the respective parameter in the matplotlib rc file.
Answered By - MCF57
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.