update 0.0.47

This commit is contained in:
guanjihuan 2022-01-14 16:57:57 +08:00
parent e853d1ed07
commit 17acf01a9b
4 changed files with 37 additions and 32 deletions

View File

@ -105,15 +105,15 @@ chern_number = guan.calculate_chern_number_for_honeycomb_lattice(hamiltonian_fun
wilson_loop_array = guan.calculate_wilson_loop(hamiltonian_function, k_min=-pi, k_max=pi, precision=100)
# read and write # Source code: https://py.guanjihuan.com/read_and_write
x, y = guan.read_one_dimensional_data(filename='a')
x, y, matrix = guan.read_two_dimensional_data(filename='a')
guan.write_one_dimensional_data(x_array, y_array, filename='a')
guan.write_two_dimensional_data(x_array, y_array, matrix, filename='a')
x_array, y_array = guan.read_one_dimensional_data(filename='a', format='txt')
x_array, y_array, matrix = guan.read_two_dimensional_data(filename='a', format='txt')
guan.write_one_dimensional_data(x_array, y_array, filename='a', format='txt')
guan.write_two_dimensional_data(x_array, y_array, matrix, filename='a', format='txt')
# plot figures # Source code: https://py.guanjihuan.com/plot_figures
guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None)
guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100)
guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300)
guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None)
guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', show=1, save=0, filename='a', format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100)
guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300)
# others # Source code: https://py.guanjihuan.com/source-code/others
guan.download_with_scihub(address=None, num=1)

View File

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

View File

@ -4,7 +4,7 @@
import numpy as np
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None):
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.20, left=0.18)
@ -28,7 +28,7 @@ def plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=
plt.show()
plt.close('all')
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', show=1, save=0, filename='a', format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
@ -67,7 +67,7 @@ def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z'
plt.show()
plt.close('all')
def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300):
def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2, right=0.75, left = 0.16)

View File

@ -4,45 +4,45 @@
import numpy as np
def read_one_dimensional_data(filename='a'):
f = open(filename+'.txt', 'r')
def read_one_dimensional_data(filename='a', format='txt'):
f = open(filename+'.'+format, 'r')
text = f.read()
f.close()
row_list = np.array(text.split('\n'))
dim_column = np.array(row_list[0].split()).shape[0]
x = np.array([])
y = np.array([])
x_array = np.array([])
y_array = np.array([])
for row in row_list:
column = np.array(row.split())
if column.shape[0] != 0:
x = np.append(x, [float(column[0])], axis=0)
x_array = np.append(x_array, [float(column[0])], axis=0)
y_row = np.zeros(dim_column-1)
for dim0 in range(dim_column-1):
y_row[dim0] = float(column[dim0+1])
if np.array(y).shape[0] == 0:
y = [y_row]
if np.array(y_array).shape[0] == 0:
y_array = [y_row]
else:
y = np.append(y, [y_row], axis=0)
return x, y
y_array = np.append(y_array, [y_row], axis=0)
return x_array, y_array
def read_two_dimensional_data(filename='a'):
f = open(filename+'.txt', 'r')
def read_two_dimensional_data(filename='a', format='txt'):
f = open(filename+'.'+format, 'r')
text = f.read()
f.close()
row_list = np.array(text.split('\n'))
dim_column = np.array(row_list[0].split()).shape[0]
x = np.array([])
y = np.array([])
x_array = np.array([])
y_array = np.array([])
matrix = np.array([])
for i0 in range(row_list.shape[0]):
column = np.array(row_list[i0].split())
if i0 == 0:
x_str = column[1::]
x = np.zeros(x_str.shape[0])
x_array = np.zeros(x_str.shape[0])
for i00 in range(x_str.shape[0]):
x[i00] = float(x_str[i00])
x_array[i00] = float(x_str[i00])
elif column.shape[0] != 0:
y = np.append(y, [float(column[0])], axis=0)
y_array = np.append(y_array, [float(column[0])], axis=0)
matrix_row = np.zeros(dim_column-1)
for dim0 in range(dim_column-1):
matrix_row[dim0] = float(column[dim0+1])
@ -50,10 +50,12 @@ def read_two_dimensional_data(filename='a'):
matrix = [matrix_row]
else:
matrix = np.append(matrix, [matrix_row], axis=0)
return x, y, matrix
return x_array, y_array, matrix
def write_one_dimensional_data(x_array, y_array, filename='a'):
with open(filename+'.txt', 'w') as f:
def write_one_dimensional_data(x_array, y_array, filename='a', format='txt'):
x_array = np.array(x_array)
y_array = np.array(y_array)
with open(filename+'.'+format, 'w') as f:
i0 = 0
for x0 in x_array:
f.write(str(x0)+' ')
@ -65,8 +67,11 @@ def write_one_dimensional_data(x_array, y_array, filename='a'):
f.write('\n')
i0 += 1
def write_two_dimensional_data(x_array, y_array, matrix, filename='a'):
with open(filename+'.txt', 'w') as f:
def write_two_dimensional_data(x_array, y_array, matrix, filename='a', format='txt'):
x_array = np.array(x_array)
y_array = np.array(y_array)
matrix = np.array(matrix)
with open(filename+'.'+format, 'w') as f:
f.write('0 ')
for x0 in x_array:
f.write(str(x0)+' ')