Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eliminating scientific notation on vertical axis of 3d plot (Python)

How can I eliminate the scientific notation on the vertical axis of a 3d plot, and replace it with integers? e.g., instead of 0.0+2.002e3, I would like 2002 My sample script is as follows:

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

yearvec = [2002, 2003, 2004]
plt.close('all')
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim3d(0, 250)
ax.set_ylim3d(0, 250)
ax.set_zlim3d(yearvec[0], yearvec[-1])
like image 934
AaronJPung Avatar asked Aug 23 '26 08:08

AaronJPung


1 Answers

Try using ax.zaxis.set_major_formatter and ax.zaxis.set_major_locator:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from matplotlib.ticker import FormatStrFormatter, MultipleLocator

yearvec = [2002, 2003, 2004, 2005]
plt.close('all')
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim3d(0, 250)
ax.set_ylim3d(0, 250)
ax.set_zlim3d(yearvec[0], yearvec[-1])

majorLocator   = MultipleLocator(1)
ax.zaxis.set_major_locator(majorLocator)
zFormatter = FormatStrFormatter('%d')
ax.zaxis.set_major_formatter(zFormatter)

This is what you want? enter image description here

like image 157
tfv Avatar answered Aug 25 '26 20:08

tfv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!