def nadir_grid(limits=None, segments=10, labels=None, axes=None, **kwargs): """ Returns a grid on *xy* plane made of quad geometric elements and its associated faces and edges colours. Ticks and labels are added to the given axes according to the extended grid settings. Parameters ---------- limits : array_like, optional Extended grid limits. segments : int, optional Edge segments count for the extended grid. labels : array_like, optional Axis labels. axes : matplotlib.axes.Axes, optional Axes to add the grid. Other Parameters ---------------- grid_face_colours : array_like, optional Grid face colours array such as `grid_face_colours = (0.25, 0.25, 0.25)`. grid_edge_colours : array_like, optional Grid edge colours array such as `grid_edge_colours = (0.25, 0.25, 0.25)`. grid_face_alpha : numeric, optional Grid face opacity value such as `grid_face_alpha = 0.1`. grid_edge_alpha : numeric, optional Grid edge opacity value such as `grid_edge_alpha = 0.5`. x_axis_colour : array_like, optional *X* axis colour array such as `x_axis_colour = (0.0, 0.0, 0.0, 1.0)`. y_axis_colour : array_like, optional *Y* axis colour array such as `y_axis_colour = (0.0, 0.0, 0.0, 1.0)`. x_ticks_colour : array_like, optional *X* axis ticks colour array such as `x_ticks_colour = (0.0, 0.0, 0.0, 0.85)`. y_ticks_colour : array_like, optional *Y* axis ticks colour array such as `y_ticks_colour = (0.0, 0.0, 0.0, 0.85)`. x_label_colour : array_like, optional *X* axis label colour array such as `x_label_colour = (0.0, 0.0, 0.0, 0.85)`. y_label_colour : array_like, optional *Y* axis label colour array such as `y_label_colour = (0.0, 0.0, 0.0, 0.85)`. ticks_and_label_location : array_like, optional Location of the *X* and *Y* axis ticks and labels such as `ticks_and_label_location = ('-x', '-y')`. Returns ------- tuple Grid quads, faces colours, edges colours. Examples -------- >>> nadir_grid(segments=1) (array([[[-1. , -1. , 0. ], [ 1. , -1. , 0. ], [ 1. , 1. , 0. ], [-1. , 1. , 0. ]], <BLANKLINE> [[-1. , -1. , 0. ], [ 0. , -1. , 0. ], [ 0. , 0. , 0. ], [-1. , 0. , 0. ]], <BLANKLINE> [[-1. , 0. , 0. ], [ 0. , 0. , 0. ], [ 0. , 1. , 0. ], [-1. , 1. , 0. ]], <BLANKLINE> [[ 0. , -1. , 0. ], [ 1. , -1. , 0. ], [ 1. , 0. , 0. ], [ 0. , 0. , 0. ]], <BLANKLINE> [[ 0. , 0. , 0. ], [ 1. , 0. , 0. ], [ 1. , 1. , 0. ], [ 0. , 1. , 0. ]], <BLANKLINE> [[-1. , -0.001, 0. ], [ 1. , -0.001, 0. ], [ 1. , 0.001, 0. ], [-1. , 0.001, 0. ]], <BLANKLINE> [[-0.001, -1. , 0. ], [ 0.001, -1. , 0. ], [ 0.001, 1. , 0. ], [-0.001, 1. , 0. ]]]), array([[ 0.25, 0.25, 0.25, 0.1 ], [ 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 1. ], [ 0. , 0. , 0. , 1. ]]), array([[ 0.5 , 0.5 , 0.5 , 0.5 ], [ 0.75, 0.75, 0.75, 0.25], [ 0.75, 0.75, 0.75, 0.25], [ 0.75, 0.75, 0.75, 0.25], [ 0.75, 0.75, 0.75, 0.25], [ 0. , 0. , 0. , 1. ], [ 0. , 0. , 0. , 1. ]])) """ if limits is None: limits = np.array([[-1, 1], [-1, 1]]) if labels is None: labels = ('x', 'y') extent = np.max(np.abs(limits[..., 1] - limits[..., 0])) settings = Structure( **{ 'grid_face_colours': (0.25, 0.25, 0.25), 'grid_edge_colours': (0.50, 0.50, 0.50), 'grid_face_alpha': 0.1, 'grid_edge_alpha': 0.5, 'x_axis_colour': (0.0, 0.0, 0.0, 1.0), 'y_axis_colour': (0.0, 0.0, 0.0, 1.0), 'x_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'y_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'x_label_colour': (0.0, 0.0, 0.0, 0.85), 'y_label_colour': (0.0, 0.0, 0.0, 0.85), 'ticks_and_label_location': ('-x', '-y') }) settings.update(**kwargs) # Outer grid. quads_g = grid( origin=(-extent / 2, -extent / 2), width=extent, height=extent, height_segments=segments, width_segments=segments) RGB_g = np.ones((quads_g.shape[0], quads_g.shape[-1])) RGB_gf = RGB_g * settings.grid_face_colours RGB_gf = np.hstack([ RGB_gf, np.full((RGB_gf.shape[0], 1), settings.grid_face_alpha, DEFAULT_FLOAT_DTYPE) ]) RGB_ge = RGB_g * settings.grid_edge_colours RGB_ge = np.hstack([ RGB_ge, np.full((RGB_ge.shape[0], 1), settings.grid_edge_alpha, DEFAULT_FLOAT_DTYPE) ]) # Inner grid. quads_gs = grid( origin=(-extent / 2, -extent / 2), width=extent, height=extent, height_segments=segments * 2, width_segments=segments * 2) RGB_gs = np.ones((quads_gs.shape[0], quads_gs.shape[-1])) RGB_gsf = RGB_gs * 0 RGB_gsf = np.hstack( [RGB_gsf, np.full((RGB_gsf.shape[0], 1), 0, DEFAULT_FLOAT_DTYPE)]) RGB_gse = np.clip(RGB_gs * settings.grid_edge_colours * 1.5, 0, 1) RGB_gse = np.hstack( (RGB_gse, np.full((RGB_gse.shape[0], 1), settings.grid_edge_alpha / 2, DEFAULT_FLOAT_DTYPE))) # Axis. thickness = extent / 1000 quad_x = grid( origin=(limits[0, 0], -thickness / 2), width=extent, height=thickness) RGB_x = np.ones((quad_x.shape[0], quad_x.shape[-1] + 1)) RGB_x = RGB_x * settings.x_axis_colour quad_y = grid( origin=(-thickness / 2, limits[1, 0]), width=thickness, height=extent) RGB_y = np.ones((quad_y.shape[0], quad_y.shape[-1] + 1)) RGB_y = RGB_y * settings.y_axis_colour if axes is not None: # Ticks. x_s = 1 if '+x' in settings.ticks_and_label_location else -1 y_s = 1 if '+y' in settings.ticks_and_label_location else -1 for i, axis in enumerate('xy'): h_a = 'center' if axis == 'x' else 'left' if x_s == 1 else 'right' v_a = 'center' ticks = list(sorted(set(quads_g[..., 0, i]))) ticks += [ticks[-1] + ticks[-1] - ticks[-2]] for tick in ticks: x = (limits[1, 1 if x_s == 1 else 0] + (x_s * extent / 25) if i else tick) y = (tick if i else limits[0, 1 if y_s == 1 else 0] + (y_s * extent / 25)) tick = DEFAULT_INT_DTYPE(tick) if DEFAULT_FLOAT_DTYPE( tick).is_integer() else tick c = settings['{0}_ticks_colour'.format(axis)] axes.text( x, y, 0, tick, 'x', horizontalalignment=h_a, verticalalignment=v_a, color=c, clip_on=True) # Labels. for i, axis in enumerate('xy'): h_a = 'center' if axis == 'x' else 'left' if x_s == 1 else 'right' v_a = 'center' x = (limits[1, 1 if x_s == 1 else 0] + (x_s * extent / 10) if i else 0) y = (0 if i else limits[0, 1 if y_s == 1 else 0] + (y_s * extent / 10)) c = settings['{0}_label_colour'.format(axis)] axes.text( x, y, 0, labels[i], 'x', horizontalalignment=h_a, verticalalignment=v_a, color=c, size=20, clip_on=True) quads = np.vstack([quads_g, quads_gs, quad_x, quad_y]) RGB_f = np.vstack([RGB_gf, RGB_gsf, RGB_x, RGB_y]) RGB_e = np.vstack([RGB_ge, RGB_gse, RGB_x, RGB_y]) return quads, RGB_f, RGB_e
def test_grid(self): """ Tests :func:`colour.plotting.geometry.grid` definition. """ np.testing.assert_almost_equal(grid(), np.array([[[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]]), decimal=7) np.testing.assert_almost_equal(grid('xz'), np.array([[[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]]]), decimal=7) np.testing.assert_almost_equal(grid('yz'), np.array([[[0, 0, 0], [0, 1, 0], [0, 1, 1], [0, 0, 1]]]), decimal=7) np.testing.assert_almost_equal( grid('xy', origin=np.array([0.2, 0.4]), width=0.2, height=0.4, depth=0.6, width_segments=3, height_segments=3), np.array([[[0.20000000, 0.40000000, 0.60000000], [0.26666667, 0.40000000, 0.60000000], [0.26666667, 0.53333333, 0.60000000], [0.20000000, 0.53333333, 0.60000000]], [[0.20000000, 0.53333333, 0.60000000], [0.26666667, 0.53333333, 0.60000000], [0.26666667, 0.66666667, 0.60000000], [0.20000000, 0.66666667, 0.60000000]], [[0.20000000, 0.66666667, 0.60000000], [0.26666667, 0.66666667, 0.60000000], [0.26666667, 0.80000000, 0.60000000], [0.20000000, 0.80000000, 0.60000000]], [[0.26666667, 0.40000000, 0.60000000], [0.33333333, 0.40000000, 0.60000000], [0.33333333, 0.53333333, 0.60000000], [0.26666667, 0.53333333, 0.60000000]], [[0.26666667, 0.53333333, 0.60000000], [0.33333333, 0.53333333, 0.60000000], [0.33333333, 0.66666667, 0.60000000], [0.26666667, 0.66666667, 0.60000000]], [[0.26666667, 0.66666667, 0.60000000], [0.33333333, 0.66666667, 0.60000000], [0.33333333, 0.80000000, 0.60000000], [0.26666667, 0.80000000, 0.60000000]], [[0.33333333, 0.40000000, 0.60000000], [0.40000000, 0.40000000, 0.60000000], [0.40000000, 0.53333333, 0.60000000], [0.33333333, 0.53333333, 0.60000000]], [[0.33333333, 0.53333333, 0.60000000], [0.40000000, 0.53333333, 0.60000000], [0.40000000, 0.66666667, 0.60000000], [0.33333333, 0.66666667, 0.60000000]], [[0.33333333, 0.66666667, 0.60000000], [0.40000000, 0.66666667, 0.60000000], [0.40000000, 0.80000000, 0.60000000], [0.33333333, 0.80000000, 0.60000000]]]), decimal=7) np.testing.assert_almost_equal( grid('xy', origin=np.array([-0.2, -0.4]), width=-0.2, height=-0.4, depth=-0.6, width_segments=3, height_segments=3), np.array([[[-0.20000000, -0.40000000, -0.60000000], [-0.26666667, -0.40000000, -0.60000000], [-0.26666667, -0.53333333, -0.60000000], [-0.20000000, -0.53333333, -0.60000000]], [[-0.20000000, -0.53333333, -0.60000000], [-0.26666667, -0.53333333, -0.60000000], [-0.26666667, -0.66666667, -0.60000000], [-0.20000000, -0.66666667, -0.60000000]], [[-0.20000000, -0.66666667, -0.60000000], [-0.26666667, -0.66666667, -0.60000000], [-0.26666667, -0.80000000, -0.60000000], [-0.20000000, -0.80000000, -0.60000000]], [[-0.26666667, -0.40000000, -0.60000000], [-0.33333333, -0.40000000, -0.60000000], [-0.33333333, -0.53333333, -0.60000000], [-0.26666667, -0.53333333, -0.60000000]], [[-0.26666667, -0.53333333, -0.60000000], [-0.33333333, -0.53333333, -0.60000000], [-0.33333333, -0.66666667, -0.60000000], [-0.26666667, -0.66666667, -0.60000000]], [[-0.26666667, -0.66666667, -0.60000000], [-0.33333333, -0.66666667, -0.60000000], [-0.33333333, -0.80000000, -0.60000000], [-0.26666667, -0.80000000, -0.60000000]], [[-0.33333333, -0.40000000, -0.60000000], [-0.40000000, -0.40000000, -0.60000000], [-0.40000000, -0.53333333, -0.60000000], [-0.33333333, -0.53333333, -0.60000000]], [[-0.33333333, -0.53333333, -0.60000000], [-0.40000000, -0.53333333, -0.60000000], [-0.40000000, -0.66666667, -0.60000000], [-0.33333333, -0.66666667, -0.60000000]], [[-0.33333333, -0.66666667, -0.60000000], [-0.40000000, -0.66666667, -0.60000000], [-0.40000000, -0.80000000, -0.60000000], [-0.33333333, -0.80000000, -0.60000000]]]), decimal=7)
def test_grid(self): """ Tests :func:`colour.plotting.geometry.grid` definition. """ np.testing.assert_almost_equal( grid(), np.array([[[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]]), decimal=7) np.testing.assert_almost_equal( grid('xz'), np.array([[[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]]]), decimal=7) np.testing.assert_almost_equal( grid('yz'), np.array([[[0, 0, 0], [0, 1, 0], [0, 1, 1], [0, 0, 1]]]), decimal=7) np.testing.assert_almost_equal( grid('xy', origin=np.array([0.2, 0.4]), width=0.2, height=0.4, depth=0.6, width_segments=3, height_segments=3), np.array( [[[0.20000000, 0.40000000, 0.60000000], [0.26666667, 0.40000000, 0.60000000], [0.26666667, 0.53333333, 0.60000000], [0.20000000, 0.53333333, 0.60000000]], [[0.20000000, 0.53333333, 0.60000000], [0.26666667, 0.53333333, 0.60000000], [0.26666667, 0.66666667, 0.60000000], [0.20000000, 0.66666667, 0.60000000]], [[0.20000000, 0.66666667, 0.60000000], [0.26666667, 0.66666667, 0.60000000], [0.26666667, 0.80000000, 0.60000000], [0.20000000, 0.80000000, 0.60000000]], [[0.26666667, 0.40000000, 0.60000000], [0.33333333, 0.40000000, 0.60000000], [0.33333333, 0.53333333, 0.60000000], [0.26666667, 0.53333333, 0.60000000]], [[0.26666667, 0.53333333, 0.60000000], [0.33333333, 0.53333333, 0.60000000], [0.33333333, 0.66666667, 0.60000000], [0.26666667, 0.66666667, 0.60000000]], [[0.26666667, 0.66666667, 0.60000000], [0.33333333, 0.66666667, 0.60000000], [0.33333333, 0.80000000, 0.60000000], [0.26666667, 0.80000000, 0.60000000]], [[0.33333333, 0.40000000, 0.60000000], [0.40000000, 0.40000000, 0.60000000], [0.40000000, 0.53333333, 0.60000000], [0.33333333, 0.53333333, 0.60000000]], [[0.33333333, 0.53333333, 0.60000000], [0.40000000, 0.53333333, 0.60000000], [0.40000000, 0.66666667, 0.60000000], [0.33333333, 0.66666667, 0.60000000]], [[0.33333333, 0.66666667, 0.60000000], [0.40000000, 0.66666667, 0.60000000], [0.40000000, 0.80000000, 0.60000000], [0.33333333, 0.80000000, 0.60000000]]] ), decimal=7) # yapf: disable np.testing.assert_almost_equal( grid('xy', origin=np.array([-0.2, -0.4]), width=-0.2, height=-0.4, depth=-0.6, width_segments=3, height_segments=3), np.array( [[[-0.20000000, -0.40000000, -0.60000000], [-0.26666667, -0.40000000, -0.60000000], [-0.26666667, -0.53333333, -0.60000000], [-0.20000000, -0.53333333, -0.60000000]], [[-0.20000000, -0.53333333, -0.60000000], [-0.26666667, -0.53333333, -0.60000000], [-0.26666667, -0.66666667, -0.60000000], [-0.20000000, -0.66666667, -0.60000000]], [[-0.20000000, -0.66666667, -0.60000000], [-0.26666667, -0.66666667, -0.60000000], [-0.26666667, -0.80000000, -0.60000000], [-0.20000000, -0.80000000, -0.60000000]], [[-0.26666667, -0.40000000, -0.60000000], [-0.33333333, -0.40000000, -0.60000000], [-0.33333333, -0.53333333, -0.60000000], [-0.26666667, -0.53333333, -0.60000000]], [[-0.26666667, -0.53333333, -0.60000000], [-0.33333333, -0.53333333, -0.60000000], [-0.33333333, -0.66666667, -0.60000000], [-0.26666667, -0.66666667, -0.60000000]], [[-0.26666667, -0.66666667, -0.60000000], [-0.33333333, -0.66666667, -0.60000000], [-0.33333333, -0.80000000, -0.60000000], [-0.26666667, -0.80000000, -0.60000000]], [[-0.33333333, -0.40000000, -0.60000000], [-0.40000000, -0.40000000, -0.60000000], [-0.40000000, -0.53333333, -0.60000000], [-0.33333333, -0.53333333, -0.60000000]], [[-0.33333333, -0.53333333, -0.60000000], [-0.40000000, -0.53333333, -0.60000000], [-0.40000000, -0.66666667, -0.60000000], [-0.33333333, -0.66666667, -0.60000000]], [[-0.33333333, -0.66666667, -0.60000000], [-0.40000000, -0.66666667, -0.60000000], [-0.40000000, -0.80000000, -0.60000000], [-0.33333333, -0.80000000, -0.60000000]]] ), decimal=7) # yapf: disable
def nadir_grid(limits=None, segments=10, labels=None, axes=None, **kwargs): """ Returns a grid on *xy* plane made of quad geometric elements and its associated faces and edges colours. Ticks and labels are added to the given axes accordingly to the extended grid settings. Parameters ---------- limits : array_like, optional Extended grid limits. segments : int, optional Edge segments count for the extended grid. labels : array_like, optional Axis labels. axes : matplotlib.axes.Axes, optional Axes to add the grid. \**kwargs : dict, optional **{'grid_face_colours', 'grid_edge_colours', 'grid_face_alpha', 'grid_edge_alpha', 'x_axis_colour', 'y_axis_colour', 'x_ticks_colour', 'y_ticks_colour', 'x_label_colour', 'y_label_colour', 'ticks_and_label_location'}**, Arguments for the nadir grid such as ``{'grid_face_colours': (0.25, 0.25, 0.25), 'grid_edge_colours': (0.50, 0.50, 0.50), 'grid_face_alpha': 0.1, 'grid_edge_alpha': 0.5, 'x_axis_colour': (0.0, 0.0, 0.0, 1.0), 'y_axis_colour': (0.0, 0.0, 0.0, 1.0), 'x_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'y_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'x_label_colour': (0.0, 0.0, 0.0, 0.85), 'y_label_colour': (0.0, 0.0, 0.0, 0.85), 'ticks_and_label_location': ('-x', '-y')}`` Returns ------- tuple Grid quads, faces colours, edges colours. Examples -------- >>> c = 'Rec. 709' >>> RGB_scatter_plot(c) # doctest: +SKIP True """ if limits is None: limits = np.array([[-1, 1], [-1, 1]]) if labels is None: labels = ('x', 'y') extent = np.max(np.abs(limits[..., 1] - limits[..., 0])) settings = Structure( **{'grid_face_colours': (0.25, 0.25, 0.25), 'grid_edge_colours': (0.50, 0.50, 0.50), 'grid_face_alpha': 0.1, 'grid_edge_alpha': 0.5, 'x_axis_colour': (0.0, 0.0, 0.0, 1.0), 'y_axis_colour': (0.0, 0.0, 0.0, 1.0), 'x_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'y_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'x_label_colour': (0.0, 0.0, 0.0, 0.85), 'y_label_colour': (0.0, 0.0, 0.0, 0.85), 'ticks_and_label_location': ('-x', '-y')}) settings.update(**kwargs) # Outer grid. quads_g = grid(origin=(-extent / 2, -extent / 2), width=extent, height=extent, height_segments=segments, width_segments=segments) RGB_g = np.ones((quads_g.shape[0], quads_g.shape[-1])) RGB_gf = RGB_g * settings.grid_face_colours RGB_gf = np.hstack((RGB_gf, np.full((RGB_gf.shape[0], 1), settings.grid_face_alpha, np.float_))) RGB_ge = RGB_g * settings.grid_edge_colours RGB_ge = np.hstack((RGB_ge, np.full((RGB_ge.shape[0], 1), settings.grid_edge_alpha, np.float_))) # Inner grid. quads_gs = grid(origin=(-extent / 2, -extent / 2), width=extent, height=extent, height_segments=segments * 2, width_segments=segments * 2) RGB_gs = np.ones((quads_gs.shape[0], quads_gs.shape[-1])) RGB_gsf = RGB_gs * 0 RGB_gsf = np.hstack((RGB_gsf, np.full((RGB_gsf.shape[0], 1, np.float_), 0))) RGB_gse = np.clip(RGB_gs * settings.grid_edge_colours * 1.5, 0, 1) RGB_gse = np.hstack((RGB_gse, np.full((RGB_gse.shape[0], 1), settings.grid_edge_alpha / 2, np.float_))) # Axis. thickness = extent / 1000 quad_x = grid(origin=(limits[0, 0], -thickness / 2), width=extent, height=thickness) RGB_x = np.ones((quad_x.shape[0], quad_x.shape[-1] + 1)) RGB_x = RGB_x * settings.x_axis_colour quad_y = grid(origin=(-thickness / 2, limits[1, 0]), width=thickness, height=extent) RGB_y = np.ones((quad_y.shape[0], quad_y.shape[-1] + 1)) RGB_y = RGB_y * settings.y_axis_colour # Ticks. x_s = 1 if '+x' in settings.ticks_and_label_location else -1 y_s = 1 if '+y' in settings.ticks_and_label_location else -1 for i, axis in enumerate('xy'): h_a = 'center' if axis == 'x' else 'left' if x_s == 1 else 'right' v_a = 'center' ticks = list(sorted(set(quads_g[..., 0, i]))) ticks += [ticks[-1] + ticks[-1] - ticks[-2]] for tick in ticks: x = (limits[1, 1 if x_s == 1 else 0] + (x_s * extent / 25) if i else tick) y = (tick if i else limits[0, 1 if y_s == 1 else 0] + (y_s * extent / 25)) tick = int(tick) if float(tick).is_integer() else tick c = settings['{0}_ticks_colour'.format(axis)] axes.text(x, y, 0, tick, 'x', horizontalalignment=h_a, verticalalignment=v_a, color=c, clip_on=True) # Labels. for i, axis in enumerate('xy'): h_a = 'center' if axis == 'x' else 'left' if x_s == 1 else 'right' v_a = 'center' x = (limits[1, 1 if x_s == 1 else 0] + (x_s * extent / 10) if i else 0) y = (0 if i else limits[0, 1 if y_s == 1 else 0] + (y_s * extent / 10)) c = settings['{0}_label_colour'.format(axis)] axes.text(x, y, 0, labels[i], 'x', horizontalalignment=h_a, verticalalignment=v_a, color=c, size=20, clip_on=True) quads = np.vstack((quads_g, quads_gs, quad_x, quad_y)) RGB_f = np.vstack((RGB_gf, RGB_gsf, RGB_x, RGB_y)) RGB_e = np.vstack((RGB_ge, RGB_gse, RGB_x, RGB_y)) return quads, RGB_f, RGB_e
def nadir_grid(limits=None, segments=10, labels=None, axes=None, **kwargs): """ Returns a grid on *xy* plane made of quad geometric elements and its associated faces and edges colours. Ticks and labels are added to the given axes accordingly to the extended grid settings. Parameters ---------- limits : array_like, optional Extended grid limits. segments : int, optional Edge segments count for the extended grid. labels : array_like, optional Axis labels. axes : matplotlib.axes.Axes, optional Axes to add the grid. \**kwargs : dict, optional **{'grid_face_colours', 'grid_edge_colours', 'grid_face_alpha', 'grid_edge_alpha', 'x_axis_colour', 'y_axis_colour', 'x_ticks_colour', 'y_ticks_colour', 'x_label_colour', 'y_label_colour', 'ticks_and_label_location'}**, Arguments for the nadir grid such as ``{'grid_face_colours': (0.25, 0.25, 0.25), 'grid_edge_colours': (0.50, 0.50, 0.50), 'grid_face_alpha': 0.1, 'grid_edge_alpha': 0.5, 'x_axis_colour': (0.0, 0.0, 0.0, 1.0), 'y_axis_colour': (0.0, 0.0, 0.0, 1.0), 'x_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'y_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'x_label_colour': (0.0, 0.0, 0.0, 0.85), 'y_label_colour': (0.0, 0.0, 0.0, 0.85), 'ticks_and_label_location': ('-x', '-y')}`` Returns ------- tuple Grid quads, faces colours, edges colours. Examples -------- >>> c = 'Rec. 709' >>> RGB_scatter_plot(c) # doctest: +SKIP True """ if limits is None: limits = np.array([[-1, 1], [-1, 1]]) if labels is None: labels = ('x', 'y') extent = np.max(np.abs(limits[..., 1] - limits[..., 0])) settings = Structure( **{ 'grid_face_colours': (0.25, 0.25, 0.25), 'grid_edge_colours': (0.50, 0.50, 0.50), 'grid_face_alpha': 0.1, 'grid_edge_alpha': 0.5, 'x_axis_colour': (0.0, 0.0, 0.0, 1.0), 'y_axis_colour': (0.0, 0.0, 0.0, 1.0), 'x_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'y_ticks_colour': (0.0, 0.0, 0.0, 0.85), 'x_label_colour': (0.0, 0.0, 0.0, 0.85), 'y_label_colour': (0.0, 0.0, 0.0, 0.85), 'ticks_and_label_location': ('-x', '-y') }) settings.update(**kwargs) # Outer grid. quads_g = grid(origin=(-extent / 2, -extent / 2), width=extent, height=extent, height_segments=segments, width_segments=segments) RGB_g = np.ones((quads_g.shape[0], quads_g.shape[-1])) RGB_gf = RGB_g * settings.grid_face_colours RGB_gf = np.hstack((RGB_gf, np.full((RGB_gf.shape[0], 1), settings.grid_face_alpha, np.float_))) RGB_ge = RGB_g * settings.grid_edge_colours RGB_ge = np.hstack((RGB_ge, np.full((RGB_ge.shape[0], 1), settings.grid_edge_alpha, np.float_))) # Inner grid. quads_gs = grid(origin=(-extent / 2, -extent / 2), width=extent, height=extent, height_segments=segments * 2, width_segments=segments * 2) RGB_gs = np.ones((quads_gs.shape[0], quads_gs.shape[-1])) RGB_gsf = RGB_gs * 0 RGB_gsf = np.hstack((RGB_gsf, np.full((RGB_gsf.shape[0], 1, np.float_), 0))) RGB_gse = np.clip(RGB_gs * settings.grid_edge_colours * 1.5, 0, 1) RGB_gse = np.hstack((RGB_gse, np.full((RGB_gse.shape[0], 1), settings.grid_edge_alpha / 2, np.float_))) # Axis. thickness = extent / 1000 quad_x = grid(origin=(limits[0, 0], -thickness / 2), width=extent, height=thickness) RGB_x = np.ones((quad_x.shape[0], quad_x.shape[-1] + 1)) RGB_x = RGB_x * settings.x_axis_colour quad_y = grid(origin=(-thickness / 2, limits[1, 0]), width=thickness, height=extent) RGB_y = np.ones((quad_y.shape[0], quad_y.shape[-1] + 1)) RGB_y = RGB_y * settings.y_axis_colour # Ticks. x_s = 1 if '+x' in settings.ticks_and_label_location else -1 y_s = 1 if '+y' in settings.ticks_and_label_location else -1 for i, axis in enumerate('xy'): h_a = 'center' if axis == 'x' else 'left' if x_s == 1 else 'right' v_a = 'center' ticks = list(sorted(set(quads_g[..., 0, i]))) ticks += [ticks[-1] + ticks[-1] - ticks[-2]] for tick in ticks: x = (limits[1, 1 if x_s == 1 else 0] + (x_s * extent / 25) if i else tick) y = (tick if i else limits[0, 1 if y_s == 1 else 0] + (y_s * extent / 25)) tick = int(tick) if float(tick).is_integer() else tick c = settings['{0}_ticks_colour'.format(axis)] axes.text(x, y, 0, tick, 'x', horizontalalignment=h_a, verticalalignment=v_a, color=c, clip_on=True) # Labels. for i, axis in enumerate('xy'): h_a = 'center' if axis == 'x' else 'left' if x_s == 1 else 'right' v_a = 'center' x = (limits[1, 1 if x_s == 1 else 0] + (x_s * extent / 10) if i else 0) y = (0 if i else limits[0, 1 if y_s == 1 else 0] + (y_s * extent / 10)) c = settings['{0}_label_colour'.format(axis)] axes.text(x, y, 0, labels[i], 'x', horizontalalignment=h_a, verticalalignment=v_a, color=c, size=20, clip_on=True) quads = np.vstack((quads_g, quads_gs, quad_x, quad_y)) RGB_f = np.vstack((RGB_gf, RGB_gsf, RGB_x, RGB_y)) RGB_e = np.vstack((RGB_ge, RGB_gse, RGB_x, RGB_y)) return quads, RGB_f, RGB_e