NLLGrid.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:nllgrid 作者: claudiodsf 项目源码 文件源码
def plot(self, slice_index=None, handle=False, figure=None, ax_xy=None,
             vmin=None, vmax=None, cmap=None, array=None):
        import matplotlib.pyplot as plt
        from matplotlib import ticker

        if array is None:
            if self.array is None:
                return
            else:
                array = self.array

        ax_xy, ax_xz, ax_yz, ax_cb = self.get_plot_axes(figure, ax_xy)
        if figure is None:
            figure = ax_xy.get_figure()

        if slice_index is None:
            slice_index = list(map(int, (self.nx/2, self.ny/2, self.nz/2)))
        if slice_index == 'max':
            slice_index = self.get_ijk_max()
        if slice_index == 'min':
            slice_index = self.get_ijk_min()

        if vmin is None:
            vmin = np.nanmin(array)
        if vmax is None:
            vmax = np.nanmax(array)

        hnd = ax_xy.imshow(np.transpose(array[:, :, slice_index[2]]),
                           vmin=vmin, vmax=vmax, cmap=cmap,
                           origin='lower', extent=self.get_xy_extent(),
                           zorder=-10)
        ax_xy.set_adjustable('box-forced')
        ax_xz.imshow(np.transpose(array[:, slice_index[1], :]),
                     vmin=vmin, vmax=vmax, cmap=cmap,
                     origin='lower', extent=self.get_xz_extent(),
                     aspect='auto', zorder=-10)
        ax_xz.set_adjustable('box-forced')
        ax_yz.imshow(array[slice_index[0], :, :],
                     vmin=vmin, vmax=vmax, cmap=cmap,
                     origin='lower', extent=self.get_zy_extent(),
                     aspect='auto', zorder=-10)
        ax_yz.set_adjustable('box-forced')

        x_slice, y_slice, z_slice = self.get_xyz(*slice_index)
        ax_xy.axhline(y_slice, color='w', linestyle='dashed', zorder=-1)
        ax_xy.axvline(x_slice, color='w', linestyle='dashed', zorder=-1)
        ax_xz.axhline(z_slice, color='w', linestyle='dashed', zorder=-1)
        ax_yz.axvline(z_slice, color='w', linestyle='dashed', zorder=-1)

        fmt = '%.1e' if np.nanmax(array) <= 0.01 else '%.2f'
        cb = figure.colorbar(
            hnd, cax=ax_cb, orientation='horizontal', format=fmt)
        cb.locator = ticker.LinearLocator(numticks=3)
        cb.update_ticks()

        if handle:
            return (ax_xy, ax_xz, ax_yz), cb
        else:
            plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号