Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualization of (continuous) secondary source contour by polygon #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion sfs/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import matplotlib.pyplot as plt
from matplotlib.patches import PathPatch
from matplotlib.path import Path
from matplotlib.collections import PatchCollection
from matplotlib.collections import PatchCollection, LineCollection
from matplotlib.colors import ListedColormap
from mpl_toolkits import axes_grid1
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
Expand Down Expand Up @@ -86,6 +87,43 @@ def secondarysource_2d(x0, n0, grid=None):
ax.add_artist(ss)


def secondarysourcecontour_2d(x0, a0=True, ax=None):
"""Draw contour of secondary source distribution as polygon.

Parameters
----------
x0 : (N, 3) array_like
Secondary source positions.
a0 : bool or (N,) array_like, optional
Active secondary sources.
ax : Axes object, optional
The loudspeakers are plotted into this `matplotlib.axes.Axes`
object or -- if not specified -- into the current axes.
"""
x0 = util.asarray_of_rows(x0)
a0 = util.asarray_1d(a0)

# colormap with black and gray to indicate active parts
cmap = ListedColormap(np.stack((.5*np.ones(3), np.zeros(3))))

# setup line collection with secondary source contour
x0 = np.append(x0, x0[0:1, :], axis=0)
points = np.array([x0[:, 0], x0[:, 1]]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap=cmap)
lc.set_linewidth(2)

# set color of line to indicate active parts
a0 = np.append(a0, a0[0])
active = np.logical_and(a0[0:-1], a0[1:])
lc.set_array(active)

# add collection of lines to current axis
if ax is None:
ax = plt.gca()
plt.gca().add_collection(lc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ax.add_collection(lc)



def loudspeaker_2d(x0, n0, a0=0.5, size=0.08, show_numbers=False, grid=None,
ax=None):
"""Draw loudspeaker symbols at given locations and angles.
Expand Down