在 3D 表面上切换 X 和 Y 轴

问题描述

我正在尝试绘制滚动相关性的表面 - 10 天到 200 天。

我有一个类似于:

st = {'10': [-0.2,0.4,0.1],'20': [0.6,0.3,0],'30': [-0.4,0.6,0.2],'40': [0.1,0.2,0.4]}
st = pd.DataFrame(data=st)
st.index = pd.date_range("20200101",periods=3)
st

            10   20   30  40
2020-01-01 -0.2  0.6 -0.4 0.1
2020-01-02  0.4  0.3  0.6 0.2
2020-01-03  0.1  0.0  0.2 0.4

我正在使用下面的代码来获得以下输出

fig = plt.figure()
fig = plt.figure(figsize=(12,10))
ax = fig.gca(projection='3d')

x = st.columns
y = np.arange(0,len(st),1)

X,Y = np.meshgrid(x,y)
Z = st

ax.plot_surface(X,Y,Z,cmap=cm.coolwarm,linewidth=0,antialiased=False)

dates = st.index

ax.xaxis.set_ticks(np.arange(10,210,10))
ax.yaxis.set_ticks(y)
ax.yaxis.set_ticklabels(dates);

enter image description here

但是,x 轴和 y 轴是相反的。我正在尝试获取沿 x 轴的日期和沿 y 轴的滚动相关性。

我试过了:

fig = plt.figure()
fig = plt.figure(figsize=(12,10))
ax = fig.gca(projection='3d')

x,y = np.meshgrid(st.index,st.columns)

z = st

ax.plot_surface(x,y,z,10))
ax.yaxis.set_ticks(y)
ax.yaxis.set_ticklabels(dates);

但我收到以下错误

ValueError:形状不匹配:对象不能广播到单个形状

谁能帮我解决我哪里出错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)