在 matplotlib trisurf 3d 图上反转 y 轴 python
Invert y axis on matplotlib trisurf 3d graph python
我正在使用 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。如果可能的话,我想在不更改数据的情况下执行此操作。
最简单的方法是使用 ax.invert_yaxis()
tmdavison 的评论正是我要找的:
ax.set_ylim(0,100)
或
ax.set_ylim(100,0)
我正在使用 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。如果可能的话,我想在不更改数据的情况下执行此操作。
最简单的方法是使用 ax.invert_yaxis()
tmdavison 的评论正是我要找的:
ax.set_ylim(0,100)
或
ax.set_ylim(100,0)