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


This Content is from Stack Overflow. Question asked by Manfred L

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.


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)

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

enter image description here

This Question was asked in StackOverflow by Manfred L and Answered by Federico Pellegatta It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?