def plot_mesh(pb): # plot mesh for macro problem coors = pb.domain.mesh.coors graph = pb.domain.mesh.get_conn(pb.domain.mesh.descs[0]) fig2 = plt.figure(figsize=(5, 6)) ax = fig2.add_subplot(111, projection='3d') for e in range(graph.shape[0]): tupleList = coors[graph[e, :], :] vertices = [[0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7]] verts = [[ tupleList[vertices[ix][iy]] for iy in range(len(vertices[0])) ] for ix in range(len(vertices))] pc3d = Poly3DCollection(verts=verts, facecolors='white', edgecolors='black', linewidths=1, alpha=0.5) ax.add_collection3d(pc3d) ax.set_xlim3d(-1.2, 1.2) ax.set_ylim3d(-1.2, 1.2) ax.set_zlim3d(-0.01, 3.2) ax.set_title('3D plot of macro system') plt.show(fig2) return None
def plot_gaps(fig_num, plot_rsc, gaps, kinds, freq_range, plot_range, show=False, clear=False, new_axes=False): """ Plot band gaps as rectangles. """ if plt is None: return fig = plt.figure(fig_num) if clear: fig.clf() if new_axes: ax = fig.add_subplot(111) else: ax = fig.gca() for ii in xrange(len(freq_range) - 1): f0, f1 = freq_range[[ii, ii + 1]] gap = gaps[ii] if isinstance(gap, list): for ig, (gmin, gmax) in enumerate(gap): kind, kind_desc = kinds[ii][ig] plot_gap(ax, ii, f0, f1, kind, kind_desc, gmin, gmax, plot_range, plot_rsc) else: gmin, gmax = gap kind, kind_desc = kinds[ii] plot_gap(ax, ii, f0, f1, kind, kind_desc, gmin, gmax, plot_range, plot_rsc) if new_axes: ax.set_xlim([freq_range[0], freq_range[-1]]) ax.set_ylim(plot_range) if show: plt.show() return fig
def plot_logs(fig_num, plot_rsc, plot_labels, freqs, logs, valid, freq_range, plot_range, draw_eigs=True, show_legend=True, show=False, clear=False, new_axes=False): """ Plot logs of min/middle/max eigs of a mass matrix. """ if plt is None: return fig = plt.figure(fig_num) if clear: fig.clf() if new_axes: ax = fig.add_subplot(111) else: ax = fig.gca() if draw_eigs: plot_eigs(fig_num, plot_rsc, plot_labels, valid, freq_range, plot_range) for ii, log in enumerate(logs): l1 = ax.plot(freqs[ii], log[:, -1], **plot_rsc['eig_max']) if log.shape[1] >= 2: l2 = ax.plot(freqs[ii], log[:, 0], **plot_rsc['eig_min']) else: l2 = None if log.shape[1] == 3: l3 = ax.plot(freqs[ii], log[:, 1], **plot_rsc['eig_mid']) else: l3 = None l1[0].set_label(plot_labels['eig_max']) if l2: l2[0].set_label(plot_labels['eig_min']) if l3: l3[0].set_label(plot_labels['eig_mid']) fmin, fmax = freqs[0][0], freqs[-1][-1] ax.plot([fmin, fmax], [0, 0], **plot_rsc['x_axis']) ax.set_xlabel(plot_labels['x_axis']) ax.set_ylabel(plot_labels['y_axis']) if new_axes: ax.set_xlim([fmin, fmax]) ax.set_ylim(plot_range) if show_legend: ax.legend() if show: plt.show() return fig
def plot_gaps(fig_num, plot_rsc, gaps, kinds, gap_ranges, freq_range, plot_range, show=False, clear=False, new_axes=False): """ Plot band gaps as rectangles. """ if plt is None: return fig = plt.figure(fig_num) if clear: fig.clf() if new_axes: ax = fig.add_subplot(111) else: ax = fig.gca() for ii in range(len(freq_range) - 1): f0, f1 = freq_range[[ii, ii + 1]] gap = gaps[ii] ranges = gap_ranges[ii] if isinstance(gap, list): for ig, (gmin, gmax) in enumerate(gap): kind, kind_desc = kinds[ii][ig] plot_gap(ax, ranges[ig], kind, kind_desc, plot_range, plot_rsc) output(ii, gmin[0], gmax[0], '%.8f' % f0, '%.8f' % f1) output(' -> %s\n %s' % (kind_desc, ranges[ig])) else: gmin, gmax = gap kind, kind_desc = kinds[ii] plot_gap(ax, ranges, kind, kind_desc, plot_range, plot_rsc) output(ii, gmin[0], gmax[0], '%.8f' % f0, '%.8f' % f1) output(' -> %s\n %s' % (kind_desc, ranges)) if new_axes: ax.set_xlim([freq_range[0], freq_range[-1]]) ax.set_ylim(plot_range) if show: plt.show() return fig
def plot_eigs(fig_num, plot_rsc, plot_labels, valid, freq_range, plot_range, show=False, clear=False, new_axes=False): """ Plot resonance/eigen-frequencies. `valid` must correspond to `freq_range` resonances : red masked resonances: dotted red """ if plt is None: return assert_(len(valid) == len(freq_range)) fig = plt.figure(fig_num) if clear: fig.clf() if new_axes: ax = fig.add_subplot(111) else: ax = fig.gca() l0 = l1 = None for ii, f in enumerate(freq_range): if valid[ii]: l0 = ax.plot([f, f], plot_range, **plot_rsc['resonance'])[0] else: l1 = ax.plot([f, f], plot_range, **plot_rsc['masked'])[0] if l0: l0.set_label(plot_labels['resonance']) if l1: l1.set_label(plot_labels['masked']) if new_axes: ax.set_xlim([freq_range[0], freq_range[-1]]) ax.set_ylim(plot_range) if show: plt.show() return fig