Skip to content
Snippets Groups Projects
Commit 8489d2f2 authored by 数学の武士's avatar 数学の武士
Browse files

fixes

parent 18bc1ecc
Branches
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -7,7 +7,7 @@ import natsort ...@@ -7,7 +7,7 @@ import natsort
import imageio import imageio
from .ProcData import ProcData from .ProcData import ProcData
import copy import copy
from matplotlib.cm import ScalarMappable import re
class Plotter: class Plotter:
ani_pngs_dir = "plotter_lib_pngs/" ani_pngs_dir = "plotter_lib_pngs/"
...@@ -55,6 +55,26 @@ class Plotter: ...@@ -55,6 +55,26 @@ class Plotter:
self.file_column_names = var_names[0] self.file_column_names = var_names[0]
def __set_fig_names(self):
if self.oname == None:
self.fig_names = copy.deepcopy(self.var)
self.fig_end = ".png"
else:
self.fig_names = copy.deepcopy(self.oname)
self.fig_end = ""
special_characters = '/'
for i in range(len(self.fig_names)):
for symbol in special_characters:
position = 0
while position < len(self.fig_names[i]):
if self.fig_names[i][position] == symbol:
self.fig_names[i] = self.fig_names[i][:position] + '\\' + self.fig_names[i][position+1:]
position += 2
else:
position += 1
def set(self, args, **kwargs): def set(self, args, **kwargs):
self.__check_arg_dim_equiv(args) self.__check_arg_dim_equiv(args)
...@@ -90,7 +110,7 @@ class Plotter: ...@@ -90,7 +110,7 @@ class Plotter:
if args.func != self.dump: if args.func != self.dump:
if args.func == self.plot or args.func == self.ani_plot or args.func == self.multiple_plot: if args.func == self.plot or args.func == self.joint_plot or args.func == self.ani_plot or args.func == self.multiple_plot:
self.ndim = 1 self.ndim = 1
elif args.func == self.plot_contour or args.func == self.ani_plot_contour: elif args.func == self.plot_contour or args.func == self.ani_plot_contour:
self.ndim = 2 self.ndim = 2
...@@ -102,18 +122,24 @@ class Plotter: ...@@ -102,18 +122,24 @@ class Plotter:
for p in self.file_data: for p in self.file_data:
p.process_file(self.ndim, self.var, self.mval) p.process_file(self.ndim, self.var, self.mval)
if args.func == self.joint_plot:
self.fig_count = len(self.file_data)
else:
self.fig_count = len(self.var) self.fig_count = len(self.var)
self.__set_fig_names()
def __plot(self): def __plot(self):
os.system("mkdir -p " + self.out) os.system("mkdir -p " + self.out)
x_name = self.file_column_names[0] x_name = self.file_column_names[0]
if self.oname == None: # if self.oname == None:
fig_names = self.var # fig_names = self.var
fig_end = ".png" # fig_end = ".png"
else: # else:
fig_names = self.oname # fig_names = self.oname
fig_end = "" # fig_end = ""
for i in range(self.fig_count): for i in range(self.fig_count):
y_name = self.var[i] y_name = self.var[i]
...@@ -125,18 +151,42 @@ class Plotter: ...@@ -125,18 +151,42 @@ class Plotter:
if self.if_manual_plot: plt.show() if self.if_manual_plot: plt.show()
else: plt.close(fig) else: plt.close(fig)
if self.if_save_result: fig.savefig(self.out + fig_names[i] + fig_end) if self.if_save_result: fig.savefig(self.out + self.fig_names[i] + self.fig_end)
def __joint_plot(self):
os.system("mkdir -p " + self.out)
x_name = self.file_column_names[0]
# if self.oname == None:
# fig_names = self.var
# fig_end = ".png"
# else:
# fig_names = self.oname
# fig_end = ""
for i in range(self.fig_count):
fig = plt.figure()
for y_name in self.var:
plt.plot(self.file_data[0].data[x_name], self.file_data[0].data[y_name], linewidth=4, label = y_name)
plt.xlabel(x_name, fontsize=10, fontweight='bold')
# plt.ylabel(y_name, fontsize=10, fontweight='bold')
plt.legend()
if self.if_manual_plot: plt.show()
else: plt.close(fig)
if self.if_save_result: fig.savefig(self.out + self.fig_names[i] + self.fig_end)
def __multiple_plot(self): def __multiple_plot(self):
os.system("mkdir -p " + self.out) os.system("mkdir -p " + self.out)
x_name = self.file_column_names[0] x_name = self.file_column_names[0]
if self.oname == None: # if self.oname == None:
fig_names = self.var # fig_names = self.var
fig_end = ".png" # fig_end = ".png"
else: # else:
fig_names = self.oname # fig_names = self.oname
fig_end = "" # fig_end = ""
for i in range(self.fig_count): for i in range(self.fig_count):
y_name = self.var[i] y_name = self.var[i]
...@@ -151,7 +201,7 @@ class Plotter: ...@@ -151,7 +201,7 @@ class Plotter:
if self.if_manual_plot: plt.show() if self.if_manual_plot: plt.show()
else: plt.close(fig) else: plt.close(fig)
if self.if_save_result: fig.savefig(self.out + fig_names[i] + fig_end) if self.if_save_result: fig.savefig(self.out + self.fig_names[i] + self.fig_end)
def __get_min_max_ax(self): def __get_min_max_ax(self):
min_max_var_vals = {var : [] for var in self.var} min_max_var_vals = {var : [] for var in self.var}
...@@ -233,12 +283,12 @@ class Plotter: ...@@ -233,12 +283,12 @@ class Plotter:
x_name = self.file_column_names[0] x_name = self.file_column_names[0]
y_name = self.file_column_names[1] y_name = self.file_column_names[1]
if self.oname == None: # if self.oname == None:
fig_names = self.var # fig_names = self.var
fig_end = ".png" # fig_end = ".png"
else: # else:
fig_names = self.oname # fig_names = self.oname
fig_end = "" # fig_end = ""
if self.max_y == None: if self.max_y == None:
max_val = {var:self.min_max_var_vals[var][1] for var in self.var} max_val = {var:self.min_max_var_vals[var][1] for var in self.var}
...@@ -278,7 +328,7 @@ class Plotter: ...@@ -278,7 +328,7 @@ class Plotter:
if self.if_manual_plot: plt.show() if self.if_manual_plot: plt.show()
else: plt.close(fig) else: plt.close(fig)
if self.if_save_result: fig.savefig(self.out + fig_names[i] + fig_end) if self.if_save_result: fig.savefig(self.out + self.fig_names[i] + self.fig_end)
def __get_min_max_bar(self): def __get_min_max_bar(self):
self.filename = natsort.natsorted(self.filename,reverse=False) self.filename = natsort.natsorted(self.filename,reverse=False)
...@@ -473,12 +523,12 @@ class Plotter: ...@@ -473,12 +523,12 @@ class Plotter:
arr = self.file_data[0].data[z_name] arr = self.file_data[0].data[z_name]
pos = self.__find_closest(arr, self.slice_position) pos = self.__find_closest(arr, self.slice_position)
if self.oname == None: # if self.oname == None:
fig_names = self.var # fig_names = self.var
fig_end = ".png" # fig_end = ".png"
else: # else:
fig_names = self.oname # fig_names = self.oname
fig_end = "" # fig_end = ""
for i in range(self.fig_count): for i in range(self.fig_count):
fig,ax=plt.subplots(1,1) fig,ax=plt.subplots(1,1)
...@@ -509,7 +559,7 @@ class Plotter: ...@@ -509,7 +559,7 @@ class Plotter:
if self.if_manual_plot: plt.show() if self.if_manual_plot: plt.show()
else: plt.close(fig) else: plt.close(fig)
if self.if_save_result: fig.savefig(self.out + fig_names[i] + fig_end) if self.if_save_result: fig.savefig(self.out + self.fig_names[i] + self.fig_end)
def dump(self): def dump(self):
self.__dump() self.__dump()
...@@ -518,6 +568,10 @@ class Plotter: ...@@ -518,6 +568,10 @@ class Plotter:
self.__get_min_max_ax() self.__get_min_max_ax()
self.__plot() self.__plot()
def joint_plot(self):
self.__get_min_max_ax()
self.__joint_plot()
def ani_plot(self): def ani_plot(self):
self.__get_min_max_ax() self.__get_min_max_ax()
self.__ani_plot() self.__ani_plot()
... ...
......
...@@ -2,6 +2,7 @@ __version__ = "0.1.0" ...@@ -2,6 +2,7 @@ __version__ = "0.1.0"
from .main import dump from .main import dump
from .main import plot from .main import plot
from .main import joint_plot
from .main import ani_plot from .main import ani_plot
from .main import plot_contour from .main import plot_contour
from .main import ani_plot_contour from .main import ani_plot_contour
... ...
......
...@@ -20,6 +20,12 @@ def plot(filename, out = './', oname = [None], var=[None], mval=[None], min_y = ...@@ -20,6 +20,12 @@ def plot(filename, out = './', oname = [None], var=[None], mval=[None], min_y =
Plot.set(args, if_manual_plot=manual_plot, if_save_result=save_result) Plot.set(args, if_manual_plot=manual_plot, if_save_result=save_result)
Plot.plot() Plot.plot()
def joint_plot(filename, out = './', oname = [None], var=[None], mval=[None], min_y = None, max_y = None):
Plot = Plotter()
args = Args([filename], Plot.joint_plot, var=var, mval=mval, oname=oname, out=out)
Plot.set(args, if_manual_plot=manual_plot, if_save_result=save_result)
Plot.joint_plot()
def multiple_plot(filename, out = './', oname = 'fig.png', var=[None], mval=[None], min_y = None, max_y = None): def multiple_plot(filename, out = './', oname = 'fig.png', var=[None], mval=[None], min_y = None, max_y = None):
Plot = Plotter() Plot = Plotter()
args = Args(filename, Plot.multiple_plot, var=var, mval=mval, oname=oname, out=out) args = Args(filename, Plot.multiple_plot, var=var, mval=mval, oname=oname, out=out)
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment