0

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.

Manfred L
  • 37
  • 6

1 Answers1

1

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

  • Yes it worked, thank you very much. At the same time I was also [inspired by others](https://blog.csdn.net/a250225/article/details/111064373) that we can set the matplotlib default font by adding `plt.rcParams['font.family'] = ['Times New Roman']` without modifying the matplotlibrc. Of course, this way doesn't have your refinement. – Manfred L Sep 19 '22 at 08:23