使用imshow 2+1维非线性薛定谔方程绘制二维图

2024-06-28 11:31:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在研究一个涉及2+1维非线性薛定谔方程的物理问题。我想在模拟的最后一个时间步绘制密度,它取决于x和y。与此模拟相对应的数据可在this h5 file中找到

我为这个情节写了以下脚本

import matplotlib.pyplot as plt
import numpy as np
import h5py as h5

data = h5.File('groundstate_interacting_2D_n50u2.h5', 'r') 
dens = data['1']['norm_dens'] 
norma = data['2']['norm'] 
en_pot = data['3']['energyp'] 
en_kin = data['4']['energyk'] 
en_int = data['5']['energyint'] 
pot_chem = data['6']['potencialchem'] 
latticex = data['7']['x'] 
latticey = data['7']['y'] 
time    = data['7']['t']  
phireal = data['7']['phireal'] 
phiimag = data['7']['phiimag'] 

#computes the square of the module of the wave-function
distr = np.power(phireal[:,:,:],2) + np.power(phiimag[:,:,:],2) 

X, Y = np.meshgrid(latticex, latticey)

fig, ax = plt.subplots()
mdr = ax.imshow(distr[400,:,:], interpolation='gaussian',cmap='plasma')
ax.set_ylabel('Y',fontsize='large', fontweight='bold')
ax.set_xlabel('X',fontsize='large', fontweight='bold')
ax.grid(False)
fig.colorbar(mdr)

plt.show()

在我的问题中,x和y都在包含32个点的晶格(latticex and latticey)中的范围(-4.0,4.0)内定义。我想知道是否有可能在我的绘图中显示相同的范围。我试过一些东西,但都不管用

enter image description here


Tags: theimportnormdataasnppltax
1条回答
网友
1楼 · 发布于 2024-06-28 11:31:32

由于没有使用imshownorm参数,因此可以使用vminvmax来指定颜色映射的上限和下限。例如:

import matplotlib.pyplot as plt
import numpy as np

a = np.outer(np.linspace(-10, 10, 100), np.linspace(-10, 10, 100))
a = (a / a.max() - 0.5) * 5.0

fig, ax = plt.subplots(1, figsize=(10,10))
m = ax.imshow(a, cmap='plasma', vmin=-4.0, vmax=4.0)
plt.show()

没有vminvmax

enter image description here

vminvmax一起:

enter image description here

这将反映在色条中,尽管为了简单起见我忽略了它们

相关问题 更多 >