This commit is contained in:
guanjihuan 2022-04-01 16:10:28 +08:00
parent 587ed76dc7
commit c80a3e2c1e
3 changed files with 32 additions and 4 deletions

View File

@ -241,12 +241,14 @@ guan.write_two_dimensional_data(x_array, y_array, matrix, filename='a', format='
# plot figures
guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None, adjust_bottom=0.2, adjust_left=0.2)
guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', format='jpg', dpi=300, style='', y_min=None, y_max=None, linewidth=None, markersize=None, adjust_bottom=0.2, adjust_left=0.2)
guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', fontsize=20, labelsize=15, 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='', fontsize=20, labelsize=15, show=1, save=0, filename='a', format='jpg', dpi=300)
guan.draw_dots_and_lines(coordinate_array, draw_dots=1, draw_lines=1, max_distance=1.5, line_style='-k', linewidth=1, dot_style='ro', markersize=3, show=0, save=1, filename='a', format='eps', dpi=300)
guan.combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filename='a', format='jpg', dpi=300)
guan.combine_three_images(image_path_array, figsize=(16,5), show=0, save=1, filename='a', format='jpg', dpi=300)

View File

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

View File

@ -1506,11 +1506,11 @@ def write_two_dimensional_data(x_array, y_array, matrix, filename='a', format='t
# Module 11: plot figures
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None, adjust_bottom=0.2, adjust_left=0.2):
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', format='jpg', dpi=300, style='', y_min=None, y_max=None, linewidth=None, markersize=None, adjust_bottom=0.2, adjust_left=0.2):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=adjust_bottom, left=adjust_left)
ax.plot(x_array, y_array, type, linewidth=linewidth, markersize=markersize)
ax.plot(x_array, y_array, style, linewidth=linewidth, markersize=markersize)
ax.grid()
ax.set_title(title, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=fontsize, fontfamily='Times New Roman')
@ -1592,6 +1592,31 @@ def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', fon
plt.show()
plt.close('all')
def draw_dots_and_lines(coordinate_array, draw_dots=1, draw_lines=1, max_distance=1.5, line_style='-k', linewidth=1, dot_style='ro', markersize=3, show=0, save=1, filename='a', format='eps', dpi=300):
import matplotlib.pyplot as plt
coordinate_array = np.array(coordinate_array)
print(coordinate_array.shape)
x_range = max(coordinate_array[:, 0])-min(coordinate_array[:, 0])
y_range = max(coordinate_array[:, 1])-min(coordinate_array[:, 1])
fig, ax = plt.subplots(figsize=(6*x_range/y_range,6))
plt.subplots_adjust(left=0, bottom=0, right=1, top=1)
plt.axis('off')
if draw_lines==1:
for i1 in range(coordinate_array.shape[0]):
for i2 in range(coordinate_array.shape[0]):
if np.sqrt((coordinate_array[i1, 0] - coordinate_array[i2, 0])**2+(coordinate_array[i1, 1] - coordinate_array[i2, 1])**2) < max_distance:
ax.plot([coordinate_array[i1, 0], coordinate_array[i2, 0]], [coordinate_array[i1, 1], coordinate_array[i2, 1]], line_style, linewidth=linewidth)
if draw_dots==1:
for i in range(coordinate_array.shape[0]):
ax.plot(coordinate_array[i, 0], coordinate_array[i, 1], dot_style, markersize=markersize)
if show==1:
plt.show()
if save==1:
if format=='eps':
plt.savefig(filename+'.'+format)
else:
plt.savefig(filename+'.'+format, dpi=dpi)
def combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filename='a', format='jpg', dpi=300):
num = np.array(image_path_array).shape[0]
if num != 2:
@ -1690,6 +1715,7 @@ def make_gif(image_path_array, filename='a', duration=0.1):
# Module 12: data processing
def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index=0):