Commit e78245aa authored by christian.foerster's avatar christian.foerster

readme.md code block formatting

parent cfb0eedf
...@@ -16,40 +16,38 @@ Examples ...@@ -16,40 +16,38 @@ Examples
Leave some example code like ... Leave some example code like ...
**Basic Example** ```python
import matplotlib.pyplot as plt
.. code-block:: python from tanks.tanks import Tank, initiate_tanks, get_levels
import matplotlib.pyplot as plt ## define network and attributes
from tanks.tanks import Tank, initiate_tanks, get_levels network_structure = {"tank_6":["tank_4","tank_5"],"tank_4":["tank_1","tank_2"],"tank_5":["tank_3"]}
attributes = {"tank_1":(10, 0.0),
## define network and attributes "tank_2":(20, 0.06),
network_structure = {"tank_6":["tank_4","tank_5"],"tank_4":["tank_1","tank_2"],"tank_5":["tank_3"]} "tank_3":(15, 0.9),
attributes = {"tank_1":(10, 0.0), "tank_4":(8, 0.3),
"tank_2":(20, 0.06), "tank_5":(44, 0.5),
"tank_3":(15, 0.9), "tank_6":(2.5, 0.0)}
"tank_4":(8, 0.3),
"tank_5":(44, 0.5), ## generate the network
"tank_6":(2.5, 0.0)} all_tanks = initiate_tanks(network_structure,attributes)
final_tank = all_tanks["tank_6"] # only the last tank is necessary to run the entire simulation
## generate the network
all_tanks = initiate_tanks(network_structure,attributes) ## simulate
final_tank = all_tanks["tank_6"] # only the last tank is necessary to run the entire simulation levels = {"tank_{}".format(k):[] for k in range(7)[1:]} # init dict for our level values
for dt in range(100):
## simulate tank_levels = get_levels(all_tanks) # retrieve levels for every iteration
levels = {"tank_{}".format(k):[] for k in range(7)[1:]} # init dict for our level values for tank_id, level in tank_levels.items(): # save the levels!
for dt in range(100): levels[tank_id].append(level) #
tank_levels = get_levels(all_tanks) # retrieve levels for every iteration final_tank.fill_tank() # open valves and let the water through to our last tank!
for tank_id, level in tank_levels.items(): # save the levels!
levels[tank_id].append(level) #
final_tank.fill_tank() # open valves and let the water through to our last tank! # checking results
fig, axis = plt.subplots(6,1,figsize = (12,8))
# checking results for idx, ax in enumerate(axis):
ax.plot(levels["tank_{}".format(idx+1)])
fig, axis = plt.subplots(6,1,figsize = (12,8)) ax.set_title("tank_{}".format(idx+1))
for idx, ax in enumerate(axis): plt.tight_layout()
ax.plot(levels["tank_{}".format(idx+1)]) plt.show()
ax.set_title("tank_{}".format(idx+1)) ```
plt.tight_layout()
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment