Пример #1
0
    def plot(self, f, fc, ss):
        ax = utilmpl.plot_template(f, fc, xlabel=self.xlabel, title=self.title,
                                scale_bar=False, bump=1.2)

        utilvtk.vtk2imshow(self.renWin, ax[0], ss)
        ax[0].axis('off')
        ax[1].axis('off')
Пример #2
0
    def plot(self, f, fc, ss):
        ax = utilmpl.plot_template(f, fc, shape=self.data.shape, xlabel=self.xlabel,
                                   title=self.title)

        # Image
        if self.cmap is 'gray':
            vmax = np.max(self.data)
            vmin = 0
        elif self.cmap is 'bwr':
            vmax = np.max(np.abs(self.data))
            vmin = -vmax

        if self.vmax is not None:
            vmax = self.vmax
            vmin = self.vmin

        ax[0].set_xlim(self.plotfov)
        ax[0].set_ylim(self.plotfov)
        ax[0].imshow(self.data.T, vmin=vmin, vmax=vmax, cmap=self.cmap,
                     extent=2*self.fov,
                     aspect='auto', interpolation='nearest', origin='lower')

        # Colorbar
        x = np.linspace(vmin, vmax, 100)
        xx, yy = np.meshgrid(x, x)

        ax[1].imshow(yy, vmin=vmin, vmax=vmax, cmap=self.cmap,
                     extent=[0,1,vmin,vmax], aspect='auto',
                     interpolation='bicubic', origin='lower')

        if self.cmap is 'gray':
            ax[1].annotate('{:.2g}'.format(np.max(vmax)), xy=(0,0), xytext=(0, 1.05), textcoords='axes fraction', va='center', ha='left')
            ax[1].annotate('0', xy=(0,0), xytext=(1.8, 0), textcoords='axes fraction', va='center', ha='left')
            ax[1].yaxis.set_ticks([0, vmax])
            ax[1].set_yticklabels(['', ''])
        elif self.cmap is 'bwr':
            ax[1].annotate('{:.2g}'.format(vmax), xy=(0,0), xytext=(0, 1.05), textcoords='axes fraction', va='center', ha='left')
            ax[1].annotate('${:.2g}$'.format(vmin), xy=(0,0), xytext=(0, -0.05), textcoords='axes fraction', va='center', ha='left')
            ax[1].yaxis.set_ticks([vmin, 0, vmax])
            ax[1].set_yticklabels(['', '', ''])

        # Colors
        ax[0].annotate('', xy=(0,0), xytext=(0.1, 0), xycoords='axes fraction', textcoords='axes fraction', arrowprops=dict(arrowstyle="-", lw=2, shrinkB=0, color='red'))
        ax[0].annotate('', xy=(0,0), xytext=(0, 0.1), xycoords='axes fraction', textcoords='axes fraction', arrowprops=dict(arrowstyle="-", lw=2, shrinkB=0, color=[0,1,0]))
Пример #3
0
    def plot(self, f, fc):
        ax = utilmpl.plot_template(f,
                                   fc,
                                   xlabel=self.xlabel,
                                   title=self.title,
                                   scale_bar=False)

        # Plot to axis
        utilvtk.vtk2imshow(self.renWin, ax[0])

        # Turn off axis outline
        ax[0].axis('off')

        # Colorbar
        vmin = -1
        vmax = 1
        x = np.linspace(vmin, vmax, 100)
        xx, yy = np.meshgrid(x, x)

        ax[1].imshow(yy,
                     vmin=vmin,
                     vmax=vmax,
                     cmap='bwr',
                     extent=[0, 1, vmin, vmax],
                     aspect='auto',
                     interpolation='bicubic',
                     origin='lower')
        ax[1].annotate('${:.2g}$'.format(np.max(vmax)),
                       xy=(0, 0),
                       xytext=(1.8, 1.0),
                       textcoords='axes fraction',
                       va='center',
                       ha='left')
        ax[1].annotate('$-{:.2g}$'.format(np.max(vmax)),
                       xy=(0, 0),
                       xytext=(1.8, 0),
                       textcoords='axes fraction',
                       va='center',
                       ha='left')
        ax[1].yaxis.set_ticks([vmin, vmax])
        ax[1].set_yticklabels(['', ''])
Пример #4
0
    def plot(self, f, fc, ss):

        # Use for placing the title
        axs = utilmpl.plot_template(f, fc, title=self.title, scale_bar=False)
        axs[0].axis('off')
        axs[1].axis('off')

        # Custom placement of axes
        fx, fy, fw, fh = fc

        # Set precise positions of axes
        w = 0.375 * fw
        h = 0.375 * fh

        # Center coordinates
        cx = fx + 0.425 * fw
        cy = fy + 0.5 * fh

        # Make three axes
        axb = f.add_axes(Bbox([[cx - w, cy - h], [cx, cy]]))
        axt = f.add_axes(Bbox([[cx - w, cy], [cx, cy + h]]))
        axc = f.add_axes(
            Bbox([[cx + 1 * w / 4, cy - h / 2], [cx + 5 * w / 4, cy + h / 2]]))
        for ax in [axb, axt, axc]:
            ax.tick_params(axis='both',
                           which='both',
                           bottom=False,
                           left=False,
                           labelbottom=False,
                           labelleft=False)

        # Scale bar and labels
        scale_shift = 0.05 * fh
        axs[0].annotate('',
                        xy=(cx - w, cy - h - scale_shift),
                        xytext=(cx, cy - h - scale_shift),
                        xycoords='figure fraction',
                        textcoords='figure fraction',
                        va='center',
                        arrowprops=dict(
                            arrowstyle="|-|, widthA=0.5, widthB=0.5",
                            shrinkA=0,
                            shrinkB=0,
                            lw=.75))
        axs[0].annotate(self.xlabel,
                        xy=(1, 1),
                        xytext=(cx - w / 2, cy - h - 0.1 * fh),
                        textcoords='figure fraction',
                        ha='center',
                        va='center',
                        rotation=0)
        axs[0].annotate(self.toplabel,
                        xy=(1, 1),
                        xytext=(cx + w / 8, cy + h / 2),
                        textcoords='figure fraction',
                        ha='center',
                        va='center',
                        rotation=0)
        axs[0].annotate(self.bottomlabel,
                        xy=(1, 1),
                        xytext=(cx + w / 8, cy - h / 2),
                        textcoords='figure fraction',
                        ha='center',
                        va='center',
                        rotation=0)

        # For labelling color scale
        if self.colormax is None:
            self.colormax = np.max(np.abs(self.data))

        # Color scale axis
        x = np.linspace(-1, 1, 100)
        y = np.linspace(-1, 1, 100)
        xx, yy = np.meshgrid(x, y)
        im = axc.imshow(utilmpl.c2rgb(xx + 1j * yy),
                        interpolation='bicubic',
                        extent=[-1, 1, -1, 1],
                        origin='lower')
        axc.axis('off')
        patch = mpl.patches.Circle((0, 0),
                                   radius=1,
                                   linewidth=0.5,
                                   facecolor='none',
                                   edgecolor='k',
                                   transform=axc.transData,
                                   clip_on=False)
        im.set_clip_path(patch)
        axc.add_patch(patch)

        axc.plot([-1, 1], [0, 0], ':k', lw=0.5)
        axc.plot([0, 0], [-1, 1], ':k', lw=0.5)
        axc.annotate('Im',
                     xy=(1, 1),
                     xytext=(0.5, 1.1),
                     textcoords='axes fraction',
                     ha='center',
                     va='center',
                     rotation=0)
        axc.annotate('Re',
                     xy=(1, 1),
                     xytext=(1.1, 0.5),
                     textcoords='axes fraction',
                     ha='center',
                     va='center',
                     rotation=0)

        axc.annotate('',
                     xy=(0.5, -0.15),
                     xytext=(1, -0.15),
                     xycoords='axes fraction',
                     textcoords='axes fraction',
                     va='center',
                     arrowprops=dict(arrowstyle="|-|, widthA=0.5, widthB=0.5",
                                     shrinkA=0,
                                     shrinkB=0,
                                     lw=.75))
        axc.annotate('{:.2g}'.format(self.colormax),
                     xy=(0, 0),
                     xytext=(0.75, -0.25),
                     textcoords='axes fraction',
                     ha='center',
                     va='center',
                     rotation=0)

        # Plot
        for i, ax in enumerate([axt, axb]):
            ax.set_xlim(self.plotfov)
            ax.set_ylim(self.plotfov)
            image = utilmpl.c2rgb(self.data[:, :, i], rmax=self.colormax)
            im = ax.imshow(image.swapaxes(0, 1),
                           interpolation='nearest',
                           extent=2 * self.fov,
                           origin='lower')
            if self.circle:
                ax.axis('off')
                patch = mpl.patches.Circle((0, 0),
                                           radius=self.plotfov[0],
                                           linewidth=0.5,
                                           facecolor='none',
                                           edgecolor='k',
                                           transform=ax.transData,
                                           clip_on=False)
                im.set_clip_path(patch)
                ax.add_patch(patch)