1 from matplotlib
import pyplot
as plt, animation, artist
4 from animationSupportClasses
import SingleLine, SinglePlot, bcolors
11 movement_per_frame = 10,
37 self.
fig = plt.figure(figsize=figure_shape)
38 self.
axs = [self.
fig.add_subplot(pos, title = title)
for pos, title
in zip(positions, titles)]
39 self.
fig.suptitle(suptitle, fontsize=12)
45 self.
fig.canvas.draw()
51 print(
"printing plot: " + str(single_plot.ax_number) +
", length: " + str(len(single_plot.single_line_list)) +
", plot type: " + single_plot.plot_type)
62 for single_line
in single_plot.single_line_list:
63 print(
"printing line: ax_number: " + str(single_line.ax_number) +
", line_number: " + str(single_line.line_number))
64 if(single_plot.plot_type ==
'bar'):
66 elif(single_plot.plot_type ==
'spring'):
76 self.
axs[ax_number].plot(\
77 single_line.x_values[single_line.x_i[0]:(single_line.x_i[1])] + single_line.starting_position[
"x"],\
78 single_line.y_values[single_line.y_i[0]:(single_line.y_i[1])] + single_line.starting_position[
"y"],\
79 marker = single_line.marker,
80 markersize = single_line.marker_size
88 single_line.print_all()
89 self.
axs[ax_number].plot(\
90 single_line.x_values[single_line.x_i[0]:(single_line.x_i[1] + 1)] + single_line.starting_position[
"x"],\
91 single_line.y_values[single_line.y_i[0]:(single_line.y_i[1] + 1)] + single_line.starting_position[
"y"],\
92 marker = single_line.marker,
93 markersize = single_line.marker_size,
94 linewidth = single_line.line_width,
95 color = single_line.color
103 self.
axs[ax_number].bar(single_line.x_values[single_line.x_i], single_line.y_values[single_line.y_i])
116 self.
axs[single_plot.ax_number].set_xlabel(single_plot.x_label)
117 self.
axs[single_plot.ax_number].set_ylabel(single_plot.y_label)
132 self.
fig.canvas.draw()
138 print(
"ax: " + str(single_plot.ax_number))
139 for single_line
in single_plot.single_line_list:
148 if(plot_type ==
'spring'):
149 self.
axs[single_line.ax_number].lines[single_line.line_number].set_xdata(single_line.x_values[single_line.x_i[0]:(single_line.x_i[1] + 1)] + single_line.starting_position[
"x"])
150 elif(self.
axs[single_line.ax_number].lines):
158 self.
axs[single_line.ax_number].lines[single_line.line_number].set_xdata(single_line.x_values[single_line.x_i[0]:single_line.x_i[1]] + single_line.starting_position[
"x"])
159 elif(plot_type ==
'bar'):
162 print(
"Please initiate ax plot before updating.")
170 if(plot_type ==
'spring'):
172 elif(self.
axs[single_line.ax_number].lines):
173 self.
axs[single_line.ax_number].lines[single_line.line_number].set_ydata(single_line.y_values[single_line.y_i[0]:single_line.y_i[1]] + single_line.starting_position[
"y"])
174 elif(plot_type ==
'bar'):
175 for rect, h
in zip(self.
axs[single_line.ax_number].patches, single_line.get_y_values()):
178 print(
"Please initiate ax plot before updating.")
187 if(self.
axs[single_plot.ax_number].lines
or single_plot.plot_type ==
'bar'):
188 self.
axs[single_plot.ax_number].set_xlim(single_plot.x_lim[
'min'], single_plot.x_lim[
'max'])
190 print(
"Please initiate ax plot before updating.")
197 if(self.
axs[single_plot.ax_number].lines
or single_plot.plot_type ==
'bar'):
198 self.
axs[single_plot.ax_number].set_ylim(single_plot.y_lim[
'min'], single_plot.y_lim[
'max'])
200 print(
"Please initiate ax plot before updating.")
209 block_spring_plot = self.
single_plots[ax_number].single_line_list[block_line_index]
210 block_line_x_values = block_spring_plot.get_x_values()
211 block_line_start_positions = block_spring_plot.get_starting_position()[
'x']
213 if(index_first_spring > 1):
214 block_line_x_values += pad_shift
215 for i, upper_spring
in enumerate(self.
single_plots[ax_number].single_line_list[index_first_spring:]):
216 upper_spring_x_values = upper_spring.get_x_values()
217 upper_spring_x_values[0] = block_line_x_values[i] + block_line_start_positions[i]
218 if(index_first_spring > 1):
219 upper_spring_x_values[1] = block_line_start_positions[i] + pad_shift
227 self.
fig.suptitle(suptitle)
233 reduce_extra_lim_amount = 3
235 ax = self.
axs[ax_number]
236 if(axis_checked ==
'y'):
238 elif(axis_checked ==
'x'):
240 compared_lims = {
'min':
None,
'max':
None}
241 for line
in ax.lines:
242 if(axis_checked ==
'y'):
243 data = line.get_ydata()
244 elif(axis_checked ==
'x'):
245 data = line.get_xdata()
247 print(bcolors.WARNING +
"Warning: tried to update non-existing axis \"" + axis_checked +
"\"" + bcolors.ENDC)
252 if(compared_lims[
'max'] ==
None or compared_lims[
'max'] < max):
253 compared_lims[
'max'] = max
254 if(compared_lims[
'min'] ==
None or compared_lims[
'min'] > min):
255 compared_lims[
'min'] = min
257 new_max = current_lims[
'max']
258 new_min = current_lims[
'min']
260 max_lim_diff = (compared_lims[
"max"] - compared_lims[
"min"])*self.
max_lim_change 261 if(compared_lims[
'max'] > current_lims[
'max']
or (current_lims[
'max'] - compared_lims[
'max']) > max_lim_diff):
262 new_max = compared_lims[
'max'] + max_lim_diff / reduce_extra_lim_amount
263 new_min = compared_lims[
'min'] - max_lim_diff / reduce_extra_lim_amount
264 elif(compared_lims[
'min'] < current_lims[
'min']
or (compared_lims[
'min'] - current_lims[
'min']) > max_lim_diff):
265 new_max = compared_lims[
'max'] + max_lim_diff / reduce_extra_lim_amount
266 new_min = compared_lims[
'min'] - max_lim_diff / reduce_extra_lim_amount
267 if(axis_checked ==
'y'):
268 ax.set_ylim(new_max, new_min)
269 elif(axis_checked ==
'x'):
270 ax.set_xlim(new_max, new_min)
306 only_shift_first = False
308 self.
shift_x_indexes(ax_number, line_number, shift_amount, only_shift_first = only_shift_first)
309 self.
shift_y_indexes(ax_number, line_number, shift_amount, only_shift_first = only_shift_first)
316 only_shift_first = False
325 only_shift_first = False
337 elif(get_axis ==
"y"):
339 new_height = np.array(new_height)
350 elif(get_axis ==
"y"):
362 line_dependencies = self.
single_plots[ax_number].single_line_list[line_number].line_dependencies
363 if(line_dependencies):
365 for i, ax_number
in enumerate(line_dependencies[
'ax_numbers']):
366 for line_dependency
in line_dependencies[
'line_numbers'][i]:
376 line_dependencies = self.
single_plots[ax_number].single_line_list[line_number].line_dependencies
377 if(line_dependencies):
379 for i, ax_number
in enumerate(line_dependencies[
'ax_numbers']):
380 for line_dependency
in line_dependencies[
'line_numbers'][i]: