def ShowImageFrame(self): if self.imageframe is None: self.imageframe = ImageFrame(self) try: self.imageframe.Show() except PyDeadObjectError: self.imageframe = Imageframe(self) self.imageframe.Show() self.imageframe.display(self.arrays[0]) self.imageframe.Raise()
import sys import wx from numpy import exp, random, arange, outer from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer(exp(-(((y-y0)/float(sy))**2)/2), exp(-(((x-x0)/float(sx))**2)/2)) ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 62. oy = -2 + y / 97.0 dat = 0.2 + (0.3*random.random(size=nx*ny).reshape(ny, nx) + 6.0*gauss2d(x, y, 90, 76, 5, 6) + 1.0*gauss2d(x, y, 180, 100, 7, 3) + 1.0*gauss2d(x, y, 175, 98, 3, 7) + 0.5*gauss2d(x, y, 181, 93, 4, 11) + 1.8*gauss2d(x, y, 270, 230, 78, 63) + 0.9*gauss2d(x, y, 240, 265, 8, 3) + 7.0*gauss2d(x, y, 40, 310, 2, 3) ) app = wx.App() frame = ImageFrame(mode='intensity') frame.display(dat, x=ox, y=oy) frame.Show() app.MainLoop()
""" example showing display of R, G, B maps """ import wx from numpy import exp, random, arange, outer, array from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer( exp( -(((y-y0)/float(sy))**2)/2), exp( -(((x-x0)/float(sx))**2)/2) ) if __name__ == '__main__': app = wx.App() frame = ImageFrame(mode='rgb') ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 100.0 oy = -1 + y / 200.0 red = 0.02 * random.random(size=nx*ny).reshape(ny, nx) red = red + (6.0*gauss2d(x, y, 90, 76, 5, 6) + 3.0*gauss2d(x, y, 165, 190, 70, 33) + 2.0*gauss2d(x, y, 180, 100, 12, 6)) green = 0.3 * random.random(size=nx*ny).reshape(ny, nx) green = green + (5.0*gauss2d(x, y, 173, 98, 4, 9) + 3.2*gauss2d(x, y, 270, 230, 78, 63)) blue = 0.1 * random.random(size=nx*ny).reshape(ny, nx) blue = blue + (2.9*gauss2d(x, y, 240, 265, 78, 23) + 3.5*gauss2d(x, y, 185, 95, 22, 11) +
import sys import wx from numpy import exp, random, arange, outer from wxmplot import ImageFrame def gauss2d(x, y, x0, y0, sx, sy): return outer(exp(-(((y - y0) / float(sy))**2) / 2), exp(-(((x - x0) / float(sx))**2) / 2)) if __name__ == '__main__': app = wx.App() frame = ImageFrame() ny, nx = 350, 400 x = arange(nx) y = arange(ny) ox = x / 100.0 oy = -1 + y / 200.0 dat = 0.3 * random.random(size=nx * ny).reshape(ny, nx) dat = dat + (16.0 * gauss2d(x, y, 190, 96, 15, 26) + 27.0 * gauss2d(x, y, 140, 210, 51, 42)) frame.display(dat, x=ox, y=oy, style='contour', contour_labels=True) frame.Show() app.MainLoop()
def plot_variable(self, var_name, var, dataset): """ Use `wxmplot` to plot the selected variables. Args: var_name: Name of the variable var: Netcdf4 `Variable`. dataset: Netcdf4 `Dataset`. """ # Remove fake dimensions. shape, dimensions = [], [] for num, name in zip(var.shape, var.dimensions): if num > 1: shape.append(num) dimensions.append(name) # Get data to plot. data = np.reshape(var[:], shape) opts = self.GetPlotOptions() cplx_mode = opts.cplx_mode if cplx_mode != "None": if shape[-1] != 2: err_msg = "cplx_mode: %s. Expecting 2 as last dimensions but got %d" % ( cplx_mode, shape[-1]) raise ValueError(err_msg) # Convert to complex then change shape and dimensions data = data[..., 0] + 1j * data[..., 1] shape = shape[:-1] dimensions = dimensions[:-1] if cplx_mode == "Abs": data = np.abs(data) elif cplx_mode == "Real": data = data.real elif cplx_mode == "Imag": data = data.imag else: raise ValueError("Wrong value for cplx_mode %s" % cplx_mode) # Plotting a scalar? if not shape: return ndim = len(shape) if ndim == 1: # Vector dim_name = dimensions[0] xx = range(len(dataset.dimensions[dim_name])) from wxmplot import PlotFrame frame = PlotFrame(parent=self) if opts.plot_mode == "line": frame.plot(xx, data) else: frame.scatterplot(xx, data) frame.set_xlabel(dim_name) frame.set_ylabel(var_name) frame.Show() elif ndim == 2: # Two dimensional array. dim_namex, dim_namey = dimensions xx, yy = range(len(dataset.dimensions[dim_namex])), range( len(dataset.dimensions[dim_namey])) mode = opts.image_mode if False: # 3d plot import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = Axes3D(fig) X, Y = np.meshgrid(xx, yy, sparse=False, indexing='ij') print(X.shape, Y.shape, data.shape) ax.plot_surface(X, Y, data) # rstride=8, cstride=8, alpha=0.3) plt.show() from wxmplot import ImageFrame frame = ImageFrame(parent=self) frame.display(data, title=var_name, style=mode, x=xx, y=yy, xlabel=dim_namex, ylabel=dim_namey) frame.Show() else: raise NotImplementedError()