-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create
geom
lib for plotting elements
Change-Id: I056ea529207457f51f4be22380f8e2d3f140b404
- Loading branch information
Showing
4 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from python import geom | ||
|
||
if __name__ == "__main__": | ||
elements = [ | ||
geom.Point([0, 0, 0]), | ||
geom.Point([1, 0, 0]), | ||
geom.Point([0, 1, 0]), | ||
geom.Point([0, 0, 1]), | ||
] | ||
|
||
fig = geom.plot(elements) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from collections.abc import Iterable | ||
from dataclasses import dataclass | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from matplotlib.axes import Axes | ||
from matplotlib.collections import PathCollection | ||
|
||
|
||
@dataclass | ||
class _Data: | ||
data: np.ndarray | ||
|
||
|
||
class Point(_Data): | ||
@property | ||
def data(self) -> np.ndarray: | ||
return self._data | ||
|
||
@data.setter | ||
def data(self, value: Iterable[float]) -> None: | ||
self._data = np.array(value, dtype=np.float64) | ||
|
||
def add_to(self, ax: Axes) -> PathCollection: | ||
return ax.scatter(*self.data) | ||
|
||
|
||
def plot(data: Iterable[Point]) -> plt.Figure: | ||
fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) | ||
ax.set_xlabel("x") | ||
ax.set_ylabel("y") | ||
ax.set_zlabel("z") | ||
|
||
for p in data: | ||
p.add_to(ax) | ||
|
||
return fig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters