def _plot_1d(pos, field, fig=None, ax=None): # pragma: no cover """Plot a 1d field.""" fig, ax = _get_fig_ax(fig, ax) title = "Field 1D: " + str(field.shape) x, __, __ = pos2xyz(pos) x = x.flatten() arg = np.argsort(x) ax.plot(x[arg], field.ravel()[arg]) ax.set_xlabel("X") ax.set_ylabel("field") ax.set_title(title) fig.show() return ax
def _plot_2d(pos, field, mesh_type, fig=None, ax=None): # pragma: no cover """Plot a 2d field.""" fig, ax = _get_fig_ax(fig, ax) title = "Field 2D " + mesh_type + ": " + str(field.shape) x, y, __ = pos2xyz(pos) if mesh_type == "unstructured": cont = ax.tricontourf(x, y, field.ravel(), levels=256) else: try: cont = ax.contourf(x, y, field.T, levels=256) except TypeError: cont = ax.contourf(x, y, field.T, 256) ax.set_xlabel("X") ax.set_ylabel("Y") ax.set_title(title) fig.colorbar(cont) fig.show() return ax
def plot_vec_field(fld, field="field", fig=None, ax=None): # pragma: no cover """ Plot a spatial random vector field. Parameters ---------- fld : :class:`Field` The given field class instance. field : :class:`str`, optional Field that should be plotted. Default: "field" fig : :class:`Figure` or :any:`None`, optional Figure to plot the axes on. If `None`, a new one will be created. Default: `None` ax : :class:`Axes` or :any:`None`, optional Axes to plot on. If `None`, a new one will be added to the figure. Default: `None` """ if fld.mesh_type is not "structured": raise RuntimeError( "Only structured vector fields are supported" + " for plotting. Please create one on a structured grid.") plot_field = getattr(fld, field) assert not (fld.pos is None or plot_field is None) norm = np.sqrt(plot_field[0, :].T**2 + plot_field[1, :].T**2) fig, ax = _get_fig_ax(fig, ax) title = "Field 2D " + fld.mesh_type + ": " + str(plot_field.shape) x, y, __ = pos2xyz(fld.pos) sp = plt.streamplot( x, y, plot_field[0, :].T, plot_field[1, :].T, color=norm, linewidth=norm / 2, ) ax.set_xlabel("X") ax.set_ylabel("Y") ax.set_title(title) fig.colorbar(sp.lines) fig.show() return ax