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

Add contour colorbar min max values

parent bfac8439
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import natsort
import imageio
from .ProcData import ProcData
import copy
from matplotlib.cm import ScalarMappable
class Plotter:
ani_pngs_dir = "plotter_lib_pngs/"
......@@ -183,7 +184,7 @@ class Plotter:
for file_name in png_names:
images.append(imageio.v2.imread(file_name))
imageio.mimsave(self.oname[0], images, fps = 5)
imageio.mimsave(self.oname[0], images, duration=20, loop = 0)
shutil.rmtree(self.ani_pngs_dir)
def __plot_contour(self):
......@@ -198,6 +199,18 @@ class Plotter:
fig_names = self.oname
fig_end = ""
if self.max_y == None:
max_val = {var:self.min_max_var_vals[var][1] for var in self.var}
else:
max_val = {var:self.max_y[i] for var, i in zip(self.var, list(range(len(self.var))))}
if self.min_y == None:
min_val = {var:self.min_max_var_vals[var][0] for var in self.var}
else:
min_val = {var:self.min_y[i] for var, i in zip(self.var, list(range(len(self.var))))}
# print(min_val, max_val)
for i in range(self.fig_count):
fig,ax=plt.subplots(1,1)
......@@ -210,7 +223,10 @@ class Plotter:
Y = self.file_data[0].data[y_name]
Z = self.file_data[0].data[self.var[i]]
cp = ax.contourf(X, Y, Z)
vmin = min_val[self.var[i]]; vmax = max_val[self.var[i]];
levels = np.linspace(vmin, vmax, 25)
cp = ax.contourf(X, Y, Z, vmin=vmin, vmax=vmax, levels=levels)
# fig.colorbar(ScalarMappable(norm=cp.norm, cmap=cp.cmap),ticks=range(min_val[self.var[i]], max_val[self.var[i]]))
fig.colorbar(cp) # Add a colorbar to a plot
ax.set_title(title)
ax.set_xlabel(x_name)
......@@ -390,6 +406,7 @@ class Plotter:
self.__avg_plot()
def plot_contour(self):
self.__get_min_max_bar()
self.__plot_contour()
def ani_plot_contour(self):
......
......@@ -4,7 +4,7 @@ from pathlib import PurePath
import natsort
import os
manual_plot=False
manual_plot=True
save_result=True
def dump(filename, var=[None], mval=[None]):
......@@ -34,9 +34,9 @@ def ani_plot(filename, out = './', oname = 'fig.gif', var=[None], mval=[None], m
Plot.set(args, if_manual_plot=manual_plot, if_save_result=save_result)
Plot.ani_plot()
def plot_contour(filename, out = './', oname = [None], var=[None], mval=[None]):
def plot_contour(filename, out = './', oname = [None], var=[None], mval=[None], min_y = None, max_y = None):
Plot = Plotter()
args = Args([filename], Plot.plot_contour, var=var, mval=mval, oname=oname, out=out)
args = Args([filename], Plot.plot_contour, var=var, mval=mval, oname=oname, out=out, min_y=min_y, max_y=max_y)
Plot.set(args, if_manual_plot=manual_plot, if_save_result=save_result)
Plot.plot_contour()
......
......@@ -4,11 +4,11 @@ if __name__ == "__main__":
setuptools.setup(
name='plotter',
version="0.2",
# install_requires=[
# "numpy>=1.23.5",
# "matplotlib >=3.6.2",
# "natsort >=8.2.0",
# "imageio >=2.22.4"],
install_requires=[
"numpy>=1.23.5",
"matplotlib >=3.6.2",
"natsort >=8.2.0",
"imageio >=2.22.4"],
packages=setuptools.find_packages(
where='.',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment