-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with methods to plot, screenshot and imshow
- Loading branch information
Showing
7 changed files
with
101 additions
and
3 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
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
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,64 @@ | ||
class BoundaryDict(dict): | ||
"A dict of boundary conditions." | ||
|
||
def plot(self, plotter=None, colors=None, **kwargs): | ||
"Plot the boundary conditions." | ||
|
||
if colors is None: | ||
import matplotlib.colors as mcolors | ||
|
||
colors = list(mcolors.TABLEAU_COLORS.values()) | ||
|
||
colors_list = [] | ||
while len(colors_list) < len(self.keys()): | ||
colors_list = [*colors_list, *colors] | ||
|
||
for (key, boundary), color in zip(self.items(), colors_list): | ||
label = key | ||
if boundary.name != "default": | ||
label = boundary.name | ||
|
||
plotter = boundary.plot(label=label, color=color, plotter=plotter, **kwargs) | ||
|
||
plotter.add_legend(size=(0.1, 0.1), bcolor="white", face="rectangle") | ||
|
||
return plotter | ||
|
||
def screenshot( | ||
self, | ||
*args, | ||
filename="boundaries.png", | ||
transparent_background=None, | ||
scale=None, | ||
colors=None, | ||
plotter=None, | ||
**kwargs, | ||
): | ||
"Take a screenshot of the boundary conditions." | ||
|
||
if plotter is None: | ||
mesh = self[list(self.keys())[0]].field.region.mesh | ||
plotter = mesh.plot(off_screen=True) | ||
|
||
plotter = self.plot(plotter=plotter, colors=colors, **kwargs) | ||
|
||
return plotter.screenshot( | ||
filename=filename, | ||
transparent_background=transparent_background, | ||
scale=scale, | ||
) | ||
|
||
def imshow(self, *args, ax=None, dpi=None, **kwargs): | ||
"""Take a screenshot of the boundary conditions, show the image data in | ||
a figure and return the ax. | ||
""" | ||
|
||
if ax is None: | ||
import matplotlib.pyplot as plt | ||
|
||
fig, ax = plt.subplots(dpi=dpi) | ||
|
||
ax.imshow(self.screenshot(*args, filename=None, **kwargs)) | ||
ax.set_axis_off() | ||
|
||
return ax |
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