23

I have draw a map with latitudes labelled but I want to set the fonts as "Times New Roman". How to make it possible?

m.drawparallels(parallels,labels=[1,0,0,0],fontsize=12)

Wang Tao
  • 233
  • 1
  • 2
  • 6

1 Answers1

60

You need to set font family using pyplot of matplotlib.

import matplotlib.pyplot as plt
csfont = {'fontname':'Times New Roman'}
// write your code related to basemap here
plt.title('title',**csfont)
plt.show()

You can also use the following to change font globally.

import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Times New Roman"
Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
  • Thanks, I have successfully changed the global font as "Times New Roman". But if I want to only set the parallels or meridians label font, what is the keyword arg? The code are in the following. from mpl_toolkits.basemap import Basemap import numpy as np import matplotlib.pyplot as plt m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,\ llcrnrlon=-180,urcrnrlon=180,resolution='c') parallels = np.arange(-90.,91.,30.) m.drawparallels(parallels,labels=[1,0,0,0],fontsize=8) plt.show() – Wang Tao Nov 22 '16 at 07:11
  • **kwargs = additional keyword arguments controlling text for labels that are passed on to the text method of the axes instance (see matplotlib.pyplot.text documentation). You can try using approach 1 to set font family for the drawparallels. – Wasi Ahmad Nov 22 '16 at 07:23
  • 8
    If you get an error saying `Font Family "Times New Roman" not found`, check [this answer](https://stackoverflow.com/a/49884009/3337089) – Nagabhushan S N Mar 14 '21 at 06:09
  • Changing font style on Ubuntu is a nightmare. For the love of god, just switch to a Windows PC and do it. "Times New Roman" is a Microsoft font. – FisNaN Mar 27 '23 at 13:34