mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-11-13 01:53:31 +01:00
Simu: add function to quickly plot geometry
This commit is contained in:
parent
03b2ddf117
commit
99cd7264f0
2 changed files with 52 additions and 10 deletions
|
@ -3,6 +3,7 @@
|
|||
import matplotlib.pyplot as plt
|
||||
from mpl_toolkits.mplot3d import axes3d
|
||||
|
||||
import location as loc
|
||||
from antenna import Receiver, Emitter
|
||||
|
||||
# 2D showcase
|
||||
|
@ -16,16 +17,7 @@ antennae = [
|
|||
]
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
ax.set_title("Geometry of Emitter(s) and Antennae")
|
||||
ax.set_ylabel("y")
|
||||
ax.set_xlabel("x")
|
||||
ax.plot(*source.x, '*', label="Emitter")
|
||||
|
||||
for j, ant in enumerate(antennae):
|
||||
ax.plot(*ant.x, '+', label="Antenna {}".format(j))
|
||||
|
||||
ax.legend()
|
||||
loc.plot_geometry(ax, [source], antennae)
|
||||
fig.show()
|
||||
|
||||
# 3D showcase
|
||||
|
|
|
@ -7,6 +7,56 @@ def distance(x1, x2):
|
|||
"""
|
||||
return np.sqrt( np.sum( (x1 - x2)**2, axis=0) )
|
||||
|
||||
def plot_geometry(ax, emitters=[], antennae=[], unit='m'):
|
||||
"""
|
||||
Show the geometry of emitters and antennae in a square plot.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ax - matplotlib.Axes
|
||||
The axis object to plot the geometry on.
|
||||
emitters - list of Locations
|
||||
The Emitter objects to plot.
|
||||
antennae - list of Locations
|
||||
The Receiver objects to plot.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ax - matplotlib.Axes
|
||||
The axis object containing the plotted geometry.
|
||||
annots - dict of list of matplotlib.text.Annotation
|
||||
The dictionary is split up into a list of annotations
|
||||
belonging to the emitters, and one for the antennae.
|
||||
"""
|
||||
|
||||
ax.grid()
|
||||
ax.set_title("Geometry of Emitter(s) and Antennae")
|
||||
ax.set_ylabel("y ({})".format(unit))
|
||||
ax.set_xlabel("x ({})".format(unit))
|
||||
ax.margins(0.3)
|
||||
ax.set_aspect('equal', 'datalim') # make it a square plot
|
||||
|
||||
annots = {}
|
||||
for k, locs in {"E": emitters, "A": antennae}.items():
|
||||
if k == "E":
|
||||
marker='*'
|
||||
prefix = k
|
||||
elif k == "A":
|
||||
marker="o"
|
||||
prefix = k
|
||||
|
||||
# create the list of annotations
|
||||
if k not in annots:
|
||||
annots[k] = []
|
||||
|
||||
# plot marker and create annotation
|
||||
for j, loc in enumerate(locs):
|
||||
label = "{}{}".format(prefix, j)
|
||||
ax.plot(*loc.x, marker=marker, label=label)
|
||||
annots[k].append(ax.annotate(label, loc.x))
|
||||
|
||||
return ax, annots
|
||||
|
||||
class Location:
|
||||
"""
|
||||
A location is a point designated by a spatial coordinate x.
|
||||
|
|
Loading…
Reference in a new issue