Python matplotlib.axes.Subplot() Examples
The following are 23
code examples of matplotlib.axes.Subplot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.axes
, or try the search function
.
Example #1
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 6 votes |
def _draw_click_instructions(subplot: plt_axes.Subplot, doubleclick=True, singleclck=True): instruction_texts = list() instruction_texts.append("Interactive instructions:") if singleclck: instruction_texts.append( "Click once on nucleotide to see its information") if doubleclick: instruction_texts.append( "Make double clock on nucleotide to cut the subgraph with its " "incoming and outgoing nucleotides in new figure") instruction_text = "\n".join(instruction_texts) subplot.annotate( instruction_text, (0.5, 0.01), xycoords="figure fraction", ha="center", va="bottom", ma="left", bbox=dict(facecolor='white', edgecolor='blue', pad=5.0))
Example #2
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 6 votes |
def _add_update_events(subplot: plt_axes.Subplot, dna_helix_graph: nx.DiGraph, nucleotide_plots: Dict[Nucleotide, _NUCLEOTIDE_PLOT]): subplot.figure.canvas.mpl_connect( 'draw_event', lambda x: subplot.pchanged()) subplot.figure.canvas.mpl_connect( 'resize_event', lambda x: subplot.pchanged()) text_initial_position = list(nucleotide_plots.values())[0].body.center text_object = subplot.text( text_initial_position[0], text_initial_position[1], "", ha="right", va="top", ma="left", bbox=dict(facecolor='white', edgecolor='blue', pad=5.0)) text_object.set_visible(False) subplot.figure.canvas.mpl_connect( 'button_press_event', partial(_remove_nucleotide_info_text, text_object=text_object)) subplot.figure.canvas.mpl_connect( 'pick_event', partial(_draw_nucleotide_info, dna_helix_graph=dna_helix_graph, text_object=text_object, subplot=subplot))
Example #3
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 6 votes |
def _draw_nucleotide_body(nucleotide, center, subplot: plt_axes.Subplot, radius=10.0): nucleotide_color, nucleotide_base_class = _get_nucleotide_color(nucleotide) nucleotide_name = nucleotide.name if len(nucleotide_name) > 10: nucleotide_name = nucleotide_name.replace("_", "_\n") nucleotide_body = patches.Circle( center, radius=radius, color=nucleotide_color) text_object = subplot.text( center[0], center[1], nucleotide_name, va="center", ha="center") text_object.draw(subplot.figure.canvas.renderer) subplot.add_patch(nucleotide_body) nucleotide_body.add_callback( partial(_nucleotide_name_callback, text_object=text_object)) nucleotide_body.set_label(":".join([nucleotide_base_class.__name__, nucleotide.name])) nucleotide_body.set_picker(True) return nucleotide_body
Example #4
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def _draw_legend(subplot: plt_axes.Subplot): nucleotide_patches, nucleotide_class_names_with_names = ( subplot.figure.gca().get_legend_handles_labels()) nucleotide_class_names = [ each_class_name_with_name.split(":")[0] for each_class_name_with_name in nucleotide_class_names_with_names] legend_labels, legend_items = zip(*OrderedDict( zip(nucleotide_class_names, nucleotide_patches)).items()) subplot.legend(legend_items, legend_labels, loc="lower right", bbox_to_anchor=(0, 0), title="Nucleotide types")
Example #5
Source File: _core.py From twitter-stock-recommendation with MIT License | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #6
Source File: _core.py From coffeegrindsize with MIT License | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #7
Source File: _core.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #8
Source File: _core.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #9
Source File: _core.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #10
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def _draw_key_text(text: str, center, theta1, theta2, radius, width, subplot: plt_axes.Subplot, **text_kwargs): text_center, theta = _get_wedge_center_and_angle( center, radius, theta1, theta2, width) text_angle = theta - 90 if text_angle > 90: text_angle = text_angle - 180 if len(text) > 10: text = text.replace("_", "_\n") text_object = subplot.annotate(text, xy=text_center, verticalalignment="center", horizontalalignment="center", rotation=text_angle, **text_kwargs) text_object.draw(subplot.figure.canvas.renderer) return text_object
Example #11
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def _draw_nucleotide_generated_keys(nucleotide, center, nucleotide_body_patch: patches.Circle, subplot: plt_axes.Subplot, radius=10.0, width=5.0): theta_min, theta_max = 180, 360 keys_color = _get_key_color("generated") generated_keys_required = nucleotide.generated_keys_required if nucleotide.dynamic_generated_keys: generated_keys_required = generated_keys_required + ["DYNAMIC"] key_patches = _draw_nucleotide_keys( generated_keys_required, nucleotide.generated_keys_optional, center, nucleotide_body_patch=nucleotide_body_patch, subplot=subplot, color=keys_color, radius=radius, width=width, theta_min=theta_min, theta_max=theta_max) return key_patches
Example #12
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def _draw_nucleotide_incoming_keys(nucleotide, center, nucleotide_body_patch: patches.Circle, subplot: plt_axes.Subplot, radius=10.0, width=5.0): theta_min, theta_max = 0, 180 keys_color = _get_key_color("incoming") incoming_keys_required = nucleotide.incoming_keys_required if nucleotide.dynamic_incoming_keys: incoming_keys_required = incoming_keys_required + ["DYNAMIC"] key_patches = _draw_nucleotide_keys( incoming_keys_required, nucleotide.incoming_keys_optional, center, nucleotide_body_patch=nucleotide_body_patch, subplot=subplot, color=keys_color, radius=radius, width=width, theta_min=theta_min, theta_max=theta_max) return key_patches
Example #13
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def _draw_dna_connections( subplot: plt_axes.Subplot, dna_helix_graph: nx.DiGraph, nucleotide_positions: Dict[Nucleotide, tuple], nucleotide_plots: Dict[Nucleotide, _NUCLEOTIDE_PLOT], verbosity: int = 0): # assumes that the coordinates are equal scaled in the view edge_label = "_dna_edge" _remove_dna_edge_patches(subplot, edge_label) nucleotide_body_patch = list(nucleotide_plots.values())[0].body body_patch_window_extent = nucleotide_body_patch.get_window_extent() if verbosity == 0: node_size_pixels = (body_patch_window_extent.width / 2 * 1.5 * subplot.figure.dpi) edge_patches = _draw_without_key_connections( dna_helix_graph, node_size_pixels, nucleotide_positions, subplot) if edge_patches: for each_edge_patch in edge_patches: each_edge_patch.set_zorder(0) else: edge_patches = _draw_with_key_connections( dna_helix_graph, nucleotide_plots, subplot) edge_patches = edge_patches or [] for each_edge_patch in edge_patches: each_edge_patch.set_label(edge_label)
Example #14
Source File: test_beyeler2019.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_AxonMapSpatial_plot(): model = AxonMapSpatial() for use_dva, xlim in zip([True, False], [(-18, 18), (-5000, 5000)]): ax = model.plot(use_dva=use_dva) npt.assert_equal(isinstance(ax, Subplot), True) npt.assert_equal(ax.get_xlim(), xlim) # Quadrants can be annotated: for ann_q, n_q in [(True, 6), (False, 0)]: fig, ax = plt.subplots() model.plot(annotate=ann_q, ax=ax) npt.assert_equal(len(ax.child_axes), int(n_q > 0)) if len(ax.child_axes) > 0: npt.assert_equal(len(ax.child_axes[0].texts), n_q) plt.close(fig)
Example #15
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def _create_figure_with_subplot(figsize=None ) -> Tuple[plt.Figure, plt_axes.Subplot]: figure = plt.figure(figsize=figsize) subplot = figure.add_subplot(111) figure.show() figure.canvas.draw() return figure, subplot
Example #16
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 5 votes |
def draw_dna_connections(dna_helix_graph: nx.DiGraph, nucleotide_plots: Dict[Nucleotide, _NUCLEOTIDE_PLOT], subplot: plt_axes.Subplot, verbosity: int = 0): """ Draw dna connections on given subplot according to verbosity level Parameters ---------- dna_helix_graph directed graph with nucleotides as nodes nucleotide_plots mapping of nucleotide to its plot subplot subplot to draw on verbosity verbosity of the visualization; if verbosity == 0, then only the connections between nucleotide are drawn, otherwise connections between nucleotide keys are drawn """ nucleotide_positions = { each_nucleotide: each_nucleotide_plot.body.center for each_nucleotide, each_nucleotide_plot in nucleotide_plots.items()} _draw_dna_connections( subplot, dna_helix_graph, nucleotide_positions, nucleotide_plots, verbosity=verbosity) subplot.add_callback( partial(_draw_dna_connections, dna_helix_graph=dna_helix_graph, nucleotide_positions=nucleotide_positions, nucleotide_plots=nucleotide_plots, verbosity=verbosity))
Example #17
Source File: _core.py From vnpy_crypto with MIT License | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #18
Source File: _core.py From recruit with Apache License 2.0 | 5 votes |
def _get_subplots(self): from matplotlib.axes import Subplot return [ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)]
Example #19
Source File: test_base.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_Percept_plot(): y_range = (-1, 1) x_range = (-2, 2) grid = Grid2D(x_range, y_range) percept = Percept(np.arange(15).reshape((3, 5, 1)), space=grid) # Basic usage of pcolor: ax = percept.plot(kind='pcolor') npt.assert_equal(isinstance(ax, Subplot), True) npt.assert_almost_equal(ax.axis(), [*x_range, *y_range]) frame = percept.get_brightest_frame() npt.assert_almost_equal(ax.collections[0].get_clim(), [frame.min(), frame.max()]) # Basic usage of hex: ax = percept.plot(kind='hex') npt.assert_equal(isinstance(ax, Subplot), True) npt.assert_almost_equal(ax.axis(), [percept.xdva[0], percept.xdva[-1], percept.ydva[0], percept.ydva[-1]]) npt.assert_almost_equal(ax.collections[0].get_clim(), [percept.data[..., 0].min(), percept.data[..., 0].max()]) # Verify color map: npt.assert_equal(ax.collections[0].cmap, plt.cm.gray) # Specify figsize: ax = percept.plot(kind='pcolor', figsize=(6, 4)) npt.assert_almost_equal(ax.figure.get_size_inches(), (6, 4)) # Invalid calls: with pytest.raises(ValueError): percept.plot(kind='invalid') with pytest.raises(TypeError): percept.plot(ax='invalid') # TODO with pytest.raises(NotImplementedError): percept.plot(time=3.3)
Example #20
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 4 votes |
def draw_nucleotide(nucleotide: Nucleotide, center: Optional[Sequence[float]] = (0, 0), subplot: Optional[plt_axes.Subplot] = None, radius: float = 10.0) -> _NUCLEOTIDE_PLOT: """ Draw nucleotide with its keys Parameters ---------- nucleotide directed graph with nucleotides as nodes center center of nucleotide on the plot subplot subplot to use radius radius of nucleotide to draw Returns ------- nucleotide_plot named tuple holding all the drawn patches for nucleotide body and it's keys """ def _callback(subplot_): for each_patch in subplot_.patches: each_patch.pchanged() if subplot is None: _, subplot = _create_figure_with_subplot() nucleotide_body = _draw_nucleotide_body( nucleotide, center, subplot, radius=radius) incoming_keys_patches = _draw_nucleotide_incoming_keys( nucleotide, center, subplot=subplot, nucleotide_body_patch=nucleotide_body, radius=radius, width=radius / 2) generated_keys_patches = _draw_nucleotide_generated_keys( nucleotide, center, subplot=subplot, nucleotide_body_patch=nucleotide_body, radius=radius, width=radius / 2) subplot.add_callback(_callback) result = _NUCLEOTIDE_PLOT(body=nucleotide_body, incoming_keys=incoming_keys_patches, generated_keys=generated_keys_patches) return result
Example #21
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 4 votes |
def draw_dna_helix(dna_helix_graph: nx.DiGraph, *, title_prefix: str = "", title_suffix: str = "", figsize=(14, 14), verbosity: int = 0 ) -> plt_axes.Subplot: """ Draw interactive dna helix All nucleotides bodies are clickable; also the font is automatic rescalable to fit it to the circles / wedges. By single click on nucleotide, the nucleotide description pops up on the right side of image. By double click on nucleotide, new figure is opened and subgraph with all connections of this nucleotide is drawn in same fashion with verbosity=2. Parameters ---------- dna_helix_graph directed graph with nucleotides as nodes title_prefix prefix that will be added to the plot title title_suffix suffix that will be added to the plot title figsize size of figure verbosity verbosity of the visualization; if verbosity == 0, then only the connections between nucleotide are drawn, otherwise connections between nucleotide keys are drawn Returns ------- subplot axes subplot with drawn dna helix Raises ------ ValueError if verbosity not in [0, 1] """ if verbosity not in [0, 1]: raise ValueError("verbosity can be 0 or 1!") figure, subplot = _create_figure_with_subplot(figsize) figure.suptitle(title_prefix + "DNA helix" + title_suffix) draw_dna_helix_on_subplot(dna_helix_graph, subplot, verbosity=verbosity) _draw_click_instructions(subplot) _add_subgraph_events(figure, dna_helix_graph) figure.canvas.blit(subplot.bbox) return subplot
Example #22
Source File: test_axon_map.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_plot_implant_on_axon_map(): ax = plot_implant_on_axon_map(ArgusII()) npt.assert_equal(isinstance(ax, Subplot), True) # Check axis limits: for xlim, ylim in zip([None, (-2000, 1500)], [(-3000, 1300), None]): ax = plot_implant_on_axon_map(ArgusII(), xlim=xlim, ylim=ylim) if xlim is None: xlim = (-4000, 4500) if ylim is None: ylim = (-2500, 3000) npt.assert_almost_equal(ax.get_xlim(), xlim) npt.assert_almost_equal(ax.get_ylim(), ylim) # Check optic disc center in both eyes: model = AxonMapSpatial() for eye in ['RE', 'LE']: for loc_od in [(15.5, 1.5), (17.9, -0.01)]: od = (-loc_od[0], loc_od[1]) if eye == 'LE' else loc_od ax = plot_implant_on_axon_map(ArgusII(eye=eye), loc_od=od) npt.assert_equal(len(ax.patches), 1) npt.assert_almost_equal(ax.patches[0].center, model.dva2ret(od)) close(ax.figure) # Electrodes and quadrants can be annotated: for ann_el, n_el in [(True, 60), (False, 0)]: for ann_q, n_q in [(True, 4), (False, 0)]: ax = plot_implant_on_axon_map(ArgusII(), annotate_implant=ann_el, annotate_quadrants=ann_q) npt.assert_equal(len(ax.texts), n_el + n_q) npt.assert_equal(len(ax.collections[0]._paths), 60) close(ax.figure) # Stimulating electrodes are marked: ax = plot_implant_on_axon_map(ArgusII(stim=np.ones(60))) # Setting upside_down flips y axis: ax = plot_implant_on_axon_map(ArgusII(), upside_down=True) npt.assert_almost_equal(ax.get_xlim(), (-4000, 4500)) npt.assert_almost_equal(ax.get_ylim(), (3000, -2500)) with pytest.raises(TypeError): plot_implant_on_axon_map(DiskElectrode(0, 0, 0, 100)) with pytest.raises(ValueError): plot_implant_on_axon_map(ArgusII(), n_bundles=0)
Example #23
Source File: test_axon_map.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_plot_axon_map(): ax = plot_axon_map() npt.assert_equal(isinstance(ax, Subplot), True) # Check axis limits: for xlim, ylim in zip([None, (-2000, 1500)], [(-3000, 1300), None]): ax = plot_axon_map(xlim=xlim, ylim=ylim) if xlim is None: xlim = (-5000, 5000) if ylim is None: ylim = (-4000, 4000) npt.assert_almost_equal(ax.get_xlim(), xlim) npt.assert_almost_equal(ax.get_ylim(), ylim) # Check optic disc center in both eyes: model = AxonMapSpatial() for eye in ['RE', 'LE']: for loc_od in [(15.5, 1.5), (-17.9, -0.01)]: ax = plot_axon_map(eye=eye, loc_od=loc_od) npt.assert_equal(len(ax.patches), 1) # Wrong sign for x-coord is automatically corrected: if eye == 'RE': od = (np.abs(loc_od[0]), loc_od[1]) else: od = (-np.abs(loc_od[0]), loc_od[1]) npt.assert_almost_equal(ax.patches[0].center, model.dva2ret(od)) close(ax.figure) # Electrodes and quadrants can be annotated: for ann_q, n_q in [(True, 4), (False, 0)]: ax = plot_axon_map(annotate=ann_q) npt.assert_equal(len(ax.texts), n_q) # Setting upside_down flips y axis: ax = plot_axon_map(upside_down=True) npt.assert_equal(ax.get_xlim(), (-5000, 5000)) npt.assert_equal(ax.get_ylim(), (4000, -4000)) with pytest.raises(ValueError): plot_axon_map(loc_od=[3]) with pytest.raises(ValueError): plot_axon_map(eye='foo') with pytest.raises(ValueError): plot_axon_map(n_bundles=0)