My Project
plotPadContinous.py
Go to the documentation of this file.
1 from analysisSharedFunctions import loadYaml, loadFile
2 from plotSetUp import setSvgLatexMatplotlibSettings, \
3  colors_qualitative_short as colors_short, \
4  linestyles, \
5  createTimeStepValues, \
6  createSliderVelocityStepValues, \
7  choseColourFromDirection, \
8  checkStepAsContinous
9 import sys
10 from matplotlib import pyplot as plt
11 
12 
14 
15 if("-m" in sys.argv):
16  multiplot_figure = plt.figure()
17  axs = [multiplot_figure.add_subplot(pos) for pos in [221, 222, 223, 224]]
18 
19 
21  yaml_file,
22  ax_number=0
23 ):
24  start = yaml_file["Parameters"]["slider_speed"]
25  increment = yaml_file["Parameters"]["increment"]
26  interval = yaml_file["Parameters"]["interval"]
27  max_time = yaml_file["Parameters"]["max_time"]
28 
29  number_of_intervals = max_time // interval
30  for i in range(0, number_of_intervals):
31  if("-m" in sys.argv):
32  axs[ax_number].axvline(x=start + increment * i,
33  linewidth=0.4,
34  color="grey",
35  alpha=0.5,
36  linestyle="-")
37  else:
38  plt.axvline(x=start + increment * i,
39  linewidth=0.4,
40  color="grey",
41  alpha=0.5,
42  linestyle="-")
43 
44 
46  time_steps,
47  pad_data,
48  yaml_file,
49  ax_number,
50  y_label="\$x\$",
51  x_label="\$t\$",
52  label="",
53  alpha=1.0,
54  x_lim=[-0.1, 2.01],
55  y_lim=[-1.6, 0.6],
56  step_as_continous=False
57 ):
58  color_index = choseColourFromDirection(yaml_file)
59  axs[ax_number].plot(time_steps, pad_data,
60  color=colors_short[color_index],
61  linestyle=linestyles[0],
62  label=label,
63  linewidth=0.6,
64  alpha=alpha
65  )
66 
67  if(step_as_continous):
68  plotVerticalStepLines(yaml_file, ax_number)
69 
70  axs[ax_number].set_xlim(x_lim[0], x_lim[1])
71  axs[ax_number].set_ylim(y_lim[0], y_lim[1])
72 
73  axs[ax_number].set_ylabel(y_label)
74  axs[ax_number].set_xlabel(x_label)
75 
76 
77 def prettyPlotPad(
78  time_steps,
79  pad_data,
80  yaml_file,
81  y_label="\$x\$",
82  x_label="\$t\$",
83  label="",
84  alpha=1.0,
85  y_lim=[-1.6, 0.6],
86  step_as_continous=False
87 ):
88  color_index = choseColourFromDirection(yaml_file)
89  plt.plot(time_steps, pad_data,
90  color=colors_short[color_index],
91  linestyle=linestyles[0],
92  label=label,
93  linewidth=0.4,
94  alpha=alpha
95  )
96 
97  if(step_as_continous):
98  plotVerticalStepLines(yaml_file)
99 
100  plt.ylim(y_lim[0], y_lim[1])
101 
102  plt.ylabel(y_label)
103  plt.xlabel(x_label)
104 
105 
106 def plot_pad(
107  run_name,
108  alpha=1.0,
109  label="Pad"
110 ):
111  yaml_file = loadYaml(run_name)
112  pad_position = loadFile(run_name, yaml_file, file_name="pad_position")
113  #pad_velocity = loadFile(run_name, yaml_file, file_name="pad_velocity")
114  step_as_continous = checkStepAsContinous(yaml_file)
115  time_steps = createSliderVelocityStepValues(pad_position, yaml_file,
116  step_as_continous)
117 
118 
119  prettyPlotPad(time_steps, pad_position, yaml_file,
120  x_label="\$\\nu\$", alpha=alpha,
121  label=label, step_as_continous=step_as_continous)
122 
123  if("-m" in sys.argv):
124  x_lims = [[-0.01, 0.15], [0.29, 0.45], [0.65, 0.81], [1.07, 1.23]]
125  for i, x_lim in enumerate(x_lims):
126  plot_multifigure(time_steps, pad_position, yaml_file,
127  x_label="\$\\nu\$", ax_number=i, x_lim=x_lim, alpha=alpha,
128  step_as_continous=step_as_continous)
129 
130 def plot_single_pad(
131  run_name
132 ):
133  plot_pad(run_name)
134  plt.legend()
135  plt.show()
136 
137 
139  run_names
140 ):
141  labels = ["Increasing", "Decreasing"]
142  alphas = [1.0, 0.8]
143  for i, run_name in enumerate(run_names):
144  plot_pad(run_name, alpha=alphas[i], label=labels[i])
145  plt.legend()
146  plt.show()
147 
148 
149 
150 def run():
151  if(len(sys.argv) == 2):
152  plot_single_pad(sys.argv[1])
153  elif(len(sys.argv) > 2):
154  if("-m" in sys.argv and "-s" in sys.argv):
155  plot_compare_pads(sys.argv[1:-2])
156  elif("-m" in sys.argv or "-s" in sys.argv):
157  plot_compare_pads(sys.argv[1:-1])
158  else:
159  plot_compare_pads(sys.argv[1:])
160 
161 
162 if __name__ == "__main__":
163  run()
def plot_pad(run_name, alpha=1.0, label="Pad")
def plot_multifigure(time_steps, pad_data, yaml_file, ax_number, y_label="\\, x_label="\t\", label="", alpha=1.0, x_lim=[-0.1, y_lim=[-1.6, step_as_continous=False)
def createSliderVelocityStepValues(block_data, yaml_file, step_as_continous=False)
Definition: plotSetUp.py:61
def plotVerticalStepLines(yaml_file, ax_number=0)
def plot_single_pad(run_name)
def plot_compare_pads(run_names)
def checkStepAsContinous(yaml_file)
Definition: plotSetUp.py:20
def loadFile(run_name, shared_names, selected='pad_position.csv')
def prettyPlotPad(time_steps, pad_data, yaml_file, y_label="\\, x_label="\t\", label="", alpha=1.0, y_lim=[-1.6, step_as_continous=False)
def choseColourFromDirection(yaml_file)
Definition: plotPadStep.py:22
def setSvgLatexMatplotlibSettings(pyplot)
Definition: plotSetUp.py:11