def plot_init(self, name, fig_specs=None, save=False):
#add a figure with a single subplot
if save==True:
import matplotlib
matplotlib.use('Agg') # non-interactive backend
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('small')
self.colors = ['-r','-b','-m','-g']
if self.fig==None:
self.fig = plt.figure(figsize=(8,4))
if fig_specs != None:
# fig_spec is a dictionary of fig adjust specs
self.fig.subplots_adjust(**fig_sepcs)
else:
self.fig.subplots_adjust(left = 0.15, bottom = 0.07,
right = 0.94, top = 0.94,
hspace = 0.14, wspace=0.20)
if type(name) != str:
raise TypeError('name should be a string')
layout = 'grid'
n = len(self.fig.axes)
if layout in ('h', 'horizontal'):
n_rows, n_cols = (1, n+1)
elif layout in ('v', 'vertical'):
n_rows, n_cols = (n+1, 1)
elif layout in ('g', 'grid'):
vector_length=n+1
n_cols = int(np.ceil(np.sqrt(vector_length)))
n_rows = int(np.ceil(vector_length/n_cols))
else:
raise ValueError('Bad layout Value')
for i in range(n):
self.fig.axes[i].change_geometry(n_rows, n_cols, i+1)
self.figsaxe[name] = self.fig.add_subplot(n_rows, n_cols, n+1)
评论列表
文章目录