【问题标题】:Is there a way to properly invert the y-axis in Python's 3DAxes plot_surface without it interfering with the x-axis?有没有办法在 Python 3D Axis plot_surface 中正确反转 y 轴而不干扰 x 轴?
【发布时间】:2020-12-15 10:20:05
【问题描述】:

我在 Python 中使用 3DAxes 来绘制曲面图。我试图操纵 y 轴从 [25 - 0] 开始,而不是从情节本身的 [0-25] 开始。到目前为止,我尝试只使用 ax.invert_yaxis(),但我的问题是这会将 x 轴更改为与 y 轴具有相同的数值。我怀疑这是因为我在代码前面使用了 np.meshgrid。

有人知道如何只反转 y 轴吗?

我有这个:

我想改变,所以 y 轴从 25 变为 0,然后表面图自然也会改变。

但是当我使用 invert_yaxis 时,我得到了这个:

这是错误的,因为 x 轴的数值也发生了变化......

代码:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d

Tcm_0 = 17.9 #K

def t(T): 
    return T/Tcm_0
my_0 = 1.25663706212e-6
Hcm_0 = 29.7 / my_0 #A/m 

def Hc2(T): 
    return Hcm_0 * (1 - np.power(t(T),1.52))

def h(H, T): 
    return H/Hc2(T)

C_1 = 350e3 #AT/mm^2

def Jc(H, T): 
    return (C_1/(my_0*H))*(1 - np.power(t(T),1.52))*(1 - np.power(t(T),2))*np.power(h(H,T),0.5)*np.power(1-h(H,T),2)
    
    
fig = plt.figure()

ax = plt.axes(projection='3d')

T = np.linspace(0,17,100)

B = np.linspace(0.1,28,100)

H = B/my_0 


T, H = np.meshgrid(T,H)

J = Jc(H,T) 

B = H*my_0

surface = ax.plot_surface(T,B,J, cmap='winter', linewidth=0)

ax.set_xbound(0, Tcm_0)

ax.set_xlabel('Temperature [K]')

ax.set_ybound(0, Hcm_0*my_0)

ax.invert_yaxis() <- This us what I dont get to work.

plt.show()

【问题讨论】:

    标签: python matplotlib plot 3d surface


    【解决方案1】:

    您可以通过手动设置轴的限制来做到这一点,无需反转任何东西。

    ax.set_ylim(25, 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 2021-06-06
      • 1970-01-01
      • 2021-06-11
      • 1970-01-01
      • 2022-01-22
      • 2019-11-20
      相关资源
      最近更新 更多