Matplotlib: Formatting dates on the x-axis in a 3D Bar graph Matplotlib: Formatting dates on the x-axis in a 3D Bar graph numpy numpy

Matplotlib: Formatting dates on the x-axis in a 3D Bar graph


There might be some confusion here, the Axes3D has the properties w_xaxis, w_yaxis and w_zaxis for the axises instead of the usual x-axis, y-axis, etc.

Tested in python 3.8.11, matplotlib 3.4.3

from mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport numpy as npimport matplotlib.dates as datesimport datetime, randomimport matplotlib.ticker as tickerdef random_date():    date = datetime.date(2008, 12, 1)    while 1:        date += datetime.timedelta(days=30)        yield (date)def format_date(x, pos=None):    return dates.num2date(x).strftime('%Y-%m-%d') #use FuncFormatter to format datesr_d = random_date()some_dates = [dates.date2num(next(r_d)) for i in range(0,20)]fig = plt.figure(figsize=(10, 10))ax = fig.add_subplot(projection='3d')for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):    xs = np.array(some_dates)    ys = np.random.rand(20)    ax.bar(xs, ys, zs=z, zdir='y', color=c, alpha=0.8,width=8)ax.w_xaxis.set_major_locator(ticker.FixedLocator(some_dates)) # I want all the dates on my xaxisax.w_xaxis.set_major_formatter(ticker.FuncFormatter(format_date))for tl in ax.w_xaxis.get_ticklabels(): # re-create what autofmt_xdate but with w_xaxis    tl.set_ha('right')    tl.set_rotation(30)     ax.set_ylabel('Series')ax.set_zlabel('Amount')plt.show()

Produces:

enter image description here