How to set the font type of zticks in matplotlib 3D plots

Viewed 26

I'm having trouble setting the tick font type for the z-axis, I can use the following code to set the font of the x-axis and y-axis to "Times New Roman", but the z-axis uses the same method to report an error.

plt.xticks(fontproperties = 'Times New Roman') 
plt.yticks(fontproperties = 'Times New Roman')
# plt.zticks(fontproperties = 'Times New Roman') #AttributeError: module 'matplotlib.pyplot' has no attribute 'zticks'

Does anyone know how to fix this? Thank you for your help.

1 Answers

Try with this solution. I was inspired by this other similar discussion:

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

# set the 3D plot
fig = plt.figure()
ax = plt.axes(projection='3d')

csfont = {'fontname':'Times New Roman'}
plt.title('title using Times New Roman',**csfont)
plt.xticks(**csfont)
plt.yticks(**csfont)

# change z-axis font type
for t in ax.zaxis.get_major_ticks(): t.label.set_font('Times New Roman')

enter image description here

Related