def get_contour_line_plot(): NPOINTS_X, NPOINTS_Y = 600, 300 # Create a scalar field to contour xs = np.linspace(-2 * np.pi, +2 * np.pi, NPOINTS_X) ys = np.linspace(-1.5 * np.pi, +1.5 * np.pi, NPOINTS_Y) x, y = np.meshgrid(xs, ys) z = scipy.special.jn(2, x) * y * x index = GridDataSource(xdata=xs, ydata=ys) index_mapper = GridMapper(range=DataRange2D(index)) value = ImageData(data=z, value_depth=1) color_mapper = dc.Blues(DataRange1D(value)) contour_plot = ContourLinePlot(index=index, index_mapper=index_mapper, value=value, colors=color_mapper, widths=list(range(1, 11)), **PLOT_DEFAULTS) add_axes(contour_plot, x_label='x', y_label='y') return contour_plot
def get_contour_poly_plot(): NPOINTS_X, NPOINTS_Y = 600, 300 # Create a scalar field to contour xs = np.linspace(-2 * np.pi, +2 * np.pi, NPOINTS_X) ys = np.linspace(-1.5 * np.pi, +1.5 * np.pi, NPOINTS_Y) x, y = np.meshgrid(xs, ys) z = scipy.special.jn(2, x) * y * x # FIXME: we have set the xbounds and ybounds manually to work around # a bug in CountourLinePlot, see comment in contour_line_plot.py at # line 112 (the workaround is the +1 at the end) xs_bounds = np.linspace(xs[0], xs[-1], z.shape[1] + 1) ys_bounds = np.linspace(ys[0], ys[-1], z.shape[0] + 1) index = GridDataSource(xdata=xs_bounds, ydata=ys_bounds) index_mapper = GridMapper(range=DataRange2D(index)) value = ImageData(data=z, value_depth=1) color_mapper = dc.Blues(DataRange1D(value)) contour_plot = ContourPolyPlot(index=index, index_mapper=index_mapper, value=value, colors=color_mapper, **PLOT_DEFAULTS) add_axes(contour_plot, x_label='x', y_label='y') return contour_plot
def get_cmap_image_plot(): # Create a scalar field to colormap NPOINTS = 200 xs = np.linspace(-2 * np.pi, +2 * np.pi, NPOINTS) ys = np.linspace(-1.5*np.pi, +1.5*np.pi, NPOINTS) x, y = np.meshgrid(xs, ys) z = scipy.special.jn(2, x)*y*x index = GridDataSource(xdata=xs, ydata=ys) index_mapper = GridMapper(range=DataRange2D(index)) color_source = ImageData(data=z, value_depth=1) color_mapper = dc.Spectral(DataRange1D(color_source)) cmap_plot = CMapImagePlot( index=index, index_mapper=index_mapper, value=color_source, value_mapper=color_mapper, **PLOT_DEFAULTS ) add_axes(cmap_plot, x_label='x', y_label='y') return cmap_plot
def get_image_from_file(): import os.path filename = os.path.join('..', '..', 'demo', 'basic', 'capitol.jpg') image_source = ImageData.fromfile(filename) w, h = image_source.get_width(), image_source.get_height() index = GridDataSource(np.arange(w), np.arange(h)) index_mapper = GridMapper( range=DataRange2D(low=(0, 0), high=(w - 1, h - 1))) image_plot = ImagePlot(index=index, value=image_source, index_mapper=index_mapper, origin='top left', **PLOT_DEFAULTS) add_axes(image_plot, x_label='x', y_label='y') return image_plot
def get_image_plot(): # Create some RGBA image data image = np.zeros((200, 400, 4), dtype=np.uint8) image[:, 0:40, 0] += 255 # Vertical red stripe image[0:25, :, 1] += 255 # Horizontal green stripe; also yellow square image[-80:, -160:, 2] += 255 # Blue square image[:, :, 3] = 255 index = GridDataSource(np.linspace(0, 4., 400), np.linspace(-1, 1., 200)) index_mapper = GridMapper(range=DataRange2D(low=(0, -1), high=(4., 1.))) image_source = ImageData(data=image, value_depth=4) image_plot = ImagePlot(index=index, value=image_source, index_mapper=index_mapper, **PLOT_DEFAULTS) add_axes(image_plot, x_label='x', y_label='y') return image_plot