import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
data = pd.read_csv('L:\\My Documents\\Desktop\\Data.csv')
dates = pd.read_csv('L:\\My Documents\\Desktop\\Dates.csv')
dates = dates['Dates'].tolist()
x = np.arange(30)
y = np.arange(139)
X, Y = np.meshgrid(x, y)
def z(u, v):
return data.ix[u][v]
Z = z(y, x).as_matrix()
curves = plt.figure().gca(projection = '3d')
curves.set_title('3D U.S. Treasury Yield Curve (Since 04-Jan-16)')
curves.set_xlabel('Date')
curves.set_ylabel('Maturity (Years)')
curves.set_zlabel('Yield (%)')
curves.view_init(elev=10, azim = -45)
surface = curves.plot_surface(Y, X, Z, linewidth = .5, cmap = cm.coolwarm)
plt.savefig('L:\\My Documents\\Desktop\\curves.png')
日期是dd-mmm-yy格式的30个日期的列表,我想用日期重新标记我的3d图的x刻度。也许不是全部30,而是6,均匀分布。
我在matplotlib库中使用了set_xtick(),但似乎无处可去。我哪里错了?