How to set the label Fonts as "Time New Roman" by drawparallels in python
Asked Answered
H

1

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)

Hanselka answered 22/11, 2016 at 5:50 Comment(0)
L
62

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"
Lung answered 22/11, 2016 at 6:8 Comment(4)
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()Hanselka
**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.Lung
If you get an error saying Font Family "Times New Roman" not found, check this answerCaryncaryo
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.Frier

© 2022 - 2024 — McMap. All rights reserved.