本文整理汇总了Python中matplotlib.axes.Subplot方法的典型用法代码示例。如果您正苦于以下问题:Python axes.Subplot方法的具体用法?Python axes.Subplot怎么用?Python axes.Subplot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.axes
的用法示例。
在下文中一共展示了axes.Subplot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_update_events
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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))
示例2: _draw_nucleotide_body
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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
示例3: _draw_click_instructions
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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))
示例4: test_AxonMapSpatial_plot
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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)
示例5: test_Percept_plot
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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)
示例6: _get_subplots
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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)]
示例7: draw_dna_connections
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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))
示例8: _create_figure_with_subplot
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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
示例9: _draw_legend
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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")
示例10: _draw_dna_connections
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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)
示例11: _draw_nucleotide_incoming_keys
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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
示例12: _draw_nucleotide_generated_keys
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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
示例13: _draw_key_text
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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
示例14: test_plot_axon_map
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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)
示例15: test_plot_implant_on_axon_map
# 需要导入模块: from matplotlib import axes [as 别名]
# 或者: from matplotlib.axes import Subplot [as 别名]
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)