简体   繁体   中英

changing fonts in matplotlib not working properly

i have a problem changing the fonts in mathplotlib. I try to build an 3d-plot and want the axis to be in arial font. Here is my code:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


# Argumentwerte als 1D Arrays erzeugen
x_Leistung = np.linspace(1050,1350,100)
y_Vorschub = np.linspace(0.8,1.2,200)

# Argumentwerte als 2D Arrays erzeugen
x_Leistung, y_Vorschub = np.meshgrid(x_Leistung, y_Vorschub)

# Interessante Daten erzeugen
z_Nahtbreite_Kupfer = 497.142+114.478*((x_Leistung-1200)/150)+16.313*(0/15)-39.4*((y_Vorschub-1)/0.2)+(0/15)*(((y_Vorschub-1)/0.2)*13.432)+(0/15)*((0/15)*(-53.144))

# Plotten
plt.figure()
ax = plt.gca(projection='3d')
ax.plot_surface(x_Leistung, y_Vorschub, z_Nahtbreite_Kupfer, cmap=plt.get_cmap("gist_gray"))

#Achsen labeln
rcfont = {'fontname' : 'Arial'}
ax.set_xlabel('$power (W)$', size='medium',**rcfont)
ax.set_ylabel('$welding speed (m/min)$', size='medium',**rcfont)
ax.set_zlabel('$weld seam width copper  (mm)$', size='medium',**rcfont)


plt.show()

there is no error, but the font is still the default one. any ideas to change this? When i try helvetica there is an error for not finding the font, but no error for Arial...

thx for the help

From what I can tell this error is raised because the font is not installed.

On windows, check the 'charmap'. All of those fonts can be used.

Helvetica is not included by default it would seem. You'll have to find it and install it. Tried and tested my end using Windows 10 and python 3.7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM