在matplotlib trisurf 3d图表Python反转y轴

时间:2015-12-01 17:35:03

标签: python matplotlib mplot3d

我正在使用matplotlib来生成3d trisurf图。我有一切工作,除了我想反转y轴,所以原点是0,0而不是0,100。我查看了matplotlib axes3d API并且无法弄清楚如何执行此操作。这是我的代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm

# my data, xs=xaxis, ys=yaxis, zs=zaxis
mortar_xs = []
cycles_ys = []
score_zs = []

#... populate my data for the 3 arrays: mortar_xs, cycles_ys, score_zs

# plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(mortar_xs,cycles_ys,score_zs,cmap=cm.coolwarm)
ax.set_zlim(bottom=0.0,top=1.0) 
ax.legend()
ax.set_xlabel("# Mortar")
ax.set_ylabel("# Goals")
ax.set_zlabel("# Score")
plt.show()

我生成的图表如下,但我需要'#Goals'或y轴反转,因此原点是0,0而不是0,100。如果可能的话,我想在不改变数据的情况下这样做。

trisurf graph

2 个答案:

答案 0 :(得分:0)

最简单的方法是使用ax.invert_yaxis()

答案 1 :(得分:0)

tmdavison的评论正是我想要的:

ax.set_ylim(0,100)

ax.set_ylim(100,0)