0

I want the font in my python plot to be consistent with the latex. I found another answer. But it doesn't work on my computer and the error is

KeyError: 'text.latex.unicode is not a valid rc parameter (see rcParams.keys() for a list of valid parameters)'

Can anyone provide me a method that can be used for current version of python?

nonlinear
  • 3
  • 2

1 Answers1

0

Try this:

import matplotlib 

font = {'family' : 'serif',
         'size'   : 12,
         'serif':  'cmr10'
         }

matplotlib.rc('font', **font)

enter image description here

user2246849
  • 4,217
  • 1
  • 12
  • 16
  • Hi! Thank you for your answer. But I encountered some user warnings as follows: UserWarning: cmr10 font should ideally be used with mathtext, set axes.formatter.use_mathtext to True UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from current font. UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) And the negative sign in the ticks was missing. – nonlinear May 07 '22 at 15:27
  • Does the rest show up fine with the correct font? If yes, add this line as well: `matplotlib.rc('axes', unicode_minus=False)` – user2246849 May 07 '22 at 15:36