PyTuflow: Difference between revisions
Content deleted Content added
Ellis Symons (talk | contribs) |
Ellis Symons (talk | contribs) |
||
Line 770:
print(message)
</pre>
Plotting water level and velocity on the same plot using a secondary axis
<pre>
import matplotlib.pyplot as plt # plotting library
import pytuflow as tu
# Initialise result class
res = tu.ResData()
# load .tpc result file
path = r'C:\TUFLOW\results\M04_5m_001.tpc'
err, message = res.load(path)
# check results were loaded successfully before continuing
if not err:
# initialise plot
fig, ax = plt.subplots()
# initialise secondary axis
ax2 = ax.twinx()
# get time series data and add to plot
elements = ['Chan_A', 'Chan_B', 'Chan_C']
result_types = ['Q', 'V']
for element in elements:
for result_type in result_types:
err_ts, mess_ts, data = res.getTimeSeriesData(element, result_type)
# check for error before plotting
if not err_ts:
x, y = data
label = '{0}: {1}'.format(result_type, element)
# plot Q on first axis, V on secondary axis
if result_type == 'Q':
# first axis
ax.plot(x, y, label=label)
else: # must be 'V'
# secondary axis
ax2.plot(x, y, label=label, linestyle='--')
else:
# error occurred getting long profile data, print error message to console
print(mess_ts)
# add legend to plot
lines, labs = ax.get_legend_handles_labels()
ax.legend(lines, labs)
# show plot
fig.show()
else:
# did not load correctly, print error message to console
print(message)
==load==
| |||