version 0.0.17

This commit is contained in:
guanjihuan
2021-08-07 19:09:07 +08:00
parent 960e363190
commit 972bde59d0
6 changed files with 53 additions and 53 deletions

View File

@@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = guan
version = 0.0.16
version = 0.0.17
author = guanjihuan
author_email = guanjihuan@163.com
description = An open source python package

View File

@@ -12,34 +12,34 @@ def calculate_eigenvalue(hamiltonian):
eigenvalue = np.sort(np.real(eigenvalue))
return eigenvalue
def calculate_eigenvalue_with_one_parameter(x, hamiltonian_function):
dim_x = np.array(x).shape[0]
def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function):
dim_x = np.array(x_array).shape[0]
i0 = 0
if np.array(hamiltonian_function(0)).shape==():
eigenvalue_array = np.zeros((dim_x, 1))
for x0 in x:
for x0 in x_array:
hamiltonian = hamiltonian_function(x0)
eigenvalue_array[i0, 0] = np.real(hamiltonian)
i0 += 1
else:
dim = np.array(hamiltonian_function(0)).shape[0]
eigenvalue_array = np.zeros((dim_x, dim))
for x0 in x:
for x0 in x_array:
hamiltonian = hamiltonian_function(x0)
eigenvalue, eigenvector = np.linalg.eig(hamiltonian)
eigenvalue_array[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
return eigenvalue_array
def calculate_eigenvalue_with_two_parameters(x, y, hamiltonian_function):
dim_x = np.array(x).shape[0]
dim_y = np.array(y).shape[0]
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function):
dim_x = np.array(x_array).shape[0]
dim_y = np.array(y_array).shape[0]
if np.array(hamiltonian_function(0,0)).shape==():
eigenvalue_array = np.zeros((dim_y, dim_x, 1))
i0 = 0
for y0 in y:
for y0 in y_array:
j0 = 0
for x0 in x:
for x0 in x_array:
hamiltonian = hamiltonian_function(x0, y0)
eigenvalue_array[i0, j0, 0] = np.real(hamiltonian)
j0 += 1
@@ -48,9 +48,9 @@ def calculate_eigenvalue_with_two_parameters(x, y, hamiltonian_function):
dim = np.array(hamiltonian_function(0, 0)).shape[0]
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
i0 = 0
for y0 in y:
for y0 in y_array:
j0 = 0
for x0 in x:
for x0 in x_array:
hamiltonian = hamiltonian_function(x0, y0)
eigenvalue, eigenvector = np.linalg.eig(hamiltonian)
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))

View File

@@ -4,20 +4,20 @@
import numpy as np
def plot(x, y, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, type='', y_min=None, y_max=None):
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, type='', y_min=None, y_max=None):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.20, left=0.18)
ax.plot(x, y, type)
ax.plot(x_array, y_array, type)
ax.grid()
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
if y_min!=None or y_max!=None:
if y_min==None:
y_min=min(y)
y_min=min(y_array)
if y_max==None:
y_max=max(y)
y_max=max(y_array)
ax.set_ylim(y_min, y_max)
ax.tick_params(labelsize=20)
labels = ax.get_xticklabels() + ax.get_yticklabels()
@@ -28,19 +28,19 @@ def plot(x, y, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, t
plt.show()
plt.close('all')
def plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None):
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
matrix = np.array(matrix)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x, y = np.meshgrid(x, y)
x_array, y_array = np.meshgrid(x_array, y_array)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
surf = ax.plot_surface(x_array, y_array, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
surf = ax.plot_surface(x_array, y_array, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
@@ -67,12 +67,12 @@ def plot_3d_surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='',
plt.show()
plt.close('all')
def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2, right=0.75, left = 0.16)
x, y = np.meshgrid(x, y)
contour = ax.contourf(x,y,matrix,cmap='jet')
x_array, y_array = np.meshgrid(x_array, y_array)
contour = ax.contourf(x_array,y_array,matrix,cmap='jet')
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')

View File

@@ -52,30 +52,30 @@ def read_two_dimensional_data(filename='a'):
matrix = np.append(matrix, [matrix_row], axis=0)
return x, y, matrix
def write_one_dimensional_data(x, y, filename='a'):
def write_one_dimensional_data(x_array, y_array, filename='a'):
with open(filename+'.txt', 'w') as f:
i0 = 0
for x0 in x:
for x0 in x_array:
f.write(str(x0)+' ')
if len(y.shape) == 1:
f.write(str(y[i0])+'\n')
elif len(y.shape) == 2:
for j0 in range(y.shape[1]):
f.write(str(y[i0, j0])+' ')
if len(y_array.shape) == 1:
f.write(str(y_array[i0])+'\n')
elif len(y_array.shape) == 2:
for j0 in range(y_array.shape[1]):
f.write(str(y_array[i0, j0])+' ')
f.write('\n')
i0 += 1
def write_two_dimensional_data(x, y, matrix, filename='a'):
def write_two_dimensional_data(x_array, y_array, matrix, filename='a'):
with open(filename+'.txt', 'w') as f:
f.write('0 ')
for x0 in x:
for x0 in x_array:
f.write(str(x0)+' ')
f.write('\n')
i0 = 0
for y0 in y:
for y0 in y_array:
f.write(str(y0))
j0 = 0
for x0 in x:
for x0 in x_array:
f.write(' '+str(matrix[i0, j0])+' ')
j0 += 1
f.write('\n')