Python matplotlib.offsetbox.AnchoredText() Examples
The following are 11
code examples of matplotlib.offsetbox.AnchoredText().
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.offsetbox
, or try the search function
.
Example #1
Source File: plot.py From mplhep with MIT License | 6 votes |
def _draw_text_bbox(ax): """ Draw legend() and fetch it's bbox """ fig = ax.figure textboxes = [] for k in ax.get_children(): if type(k) == AnchoredText: textboxes.append(k) if len(textboxes) > 1: print("Warning: More than one textbox found") for box in textboxes: if box.loc in [1, 2]: bbox = box.get_tightbbox(fig.canvas.renderer) else: bbox = textboxes[0].get_tightbbox(fig.canvas.renderer) return bbox
Example #2
Source File: simple_anchored_artists.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def draw_text(ax): """ Draw two text-boxes, anchored by different corners to the upper-left corner of the figure. """ from matplotlib.offsetbox import AnchoredText at = AnchoredText("Figure 1a", loc='upper left', prop=dict(size=8), frameon=True, ) at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") ax.add_artist(at) at2 = AnchoredText("Figure 1(b)", loc='lower left', prop=dict(size=8), frameon=True, bbox_to_anchor=(0., 1.), bbox_transform=ax.transAxes ) at2.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") ax.add_artist(at2)
Example #3
Source File: plot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _subplot_label(self, axis): layout_num = self.layout_num if self.subplot else 1 if self.sublabel_format and not self.adjoined and layout_num > 0: from matplotlib.offsetbox import AnchoredText labels = {} if '{Alpha}' in self.sublabel_format: labels['Alpha'] = int_to_alpha(layout_num-1) elif '{alpha}' in self.sublabel_format: labels['alpha'] = int_to_alpha(layout_num-1, upper=False) elif '{numeric}' in self.sublabel_format: labels['numeric'] = self.layout_num elif '{Roman}' in self.sublabel_format: labels['Roman'] = int_to_roman(layout_num) elif '{roman}' in self.sublabel_format: labels['roman'] = int_to_roman(layout_num).lower() at = AnchoredText(self.sublabel_format.format(**labels), loc=3, bbox_to_anchor=self.sublabel_position, frameon=False, prop=dict(size=self.sublabel_size, weight='bold'), bbox_transform=axis.transAxes) at.patch.set_visible(False) axis.add_artist(at) sublabel = at.txt.get_children()[0] self.handles['sublabel'] = sublabel self.handles['bbox_extra_artists'] += [sublabel]
Example #4
Source File: __init__.py From radvel with MIT License | 6 votes |
def add_anchored(*args, **kwargs): """ Add text at a particular location in the current Axes Args: s (string): text loc (string): location code pad (float [optional]): pad between the text and the frame as fraction of the font size borderpad (float [optional]): pad between the frame and the axes (or *bbox_to_anchor*) prop (matplotlib.font_manager.FontProperties): font properties """ bbox = {} if 'bbox' in kwargs: bbox = kwargs.pop('bbox') at = AnchoredText(*args, **kwargs) if len(bbox.keys()) > 0: pl.setp(at.patch, **bbox) ax = pl.gca() ax.add_artist(at)
Example #5
Source File: heatmap.py From python-wifi-survey-heatmap with GNU Affero General Public License v3.0 | 5 votes |
def _add_inner_title(self, ax, title, loc, size=None, **kwargs): if size is None: size = dict(size=pp.rcParams['legend.fontsize']) at = AnchoredText( title, loc=loc, prop=size, pad=0., borderpad=0.5, frameon=False, **kwargs ) at.set_zorder(200) ax.add_artist(at) at.txt._text.set_path_effects( [withStroke(foreground="w", linewidth=3)] ) return at
Example #6
Source File: plot.py From mplhep with MIT License | 5 votes |
def yscale_text(ax=None): """ Automatically scale y-axis up to fit AnchoredText """ if ax is None: ax = plt.gca() while overlap(ax, _draw_text_bbox(ax)) > 0: ax.set_ylim(ax.get_ylim()[0], ax.get_ylim()[-1] * 1.1) ax.figure.canvas.draw() return ax
Example #7
Source File: demo_axes_grid2.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_inner_title(ax, title, loc, size=None, **kwargs): from matplotlib.offsetbox import AnchoredText from matplotlib.patheffects import withStroke if size is None: size = dict(size=plt.rcParams['legend.fontsize']) at = AnchoredText(title, loc=loc, prop=size, pad=0., borderpad=0.5, frameon=False, **kwargs) ax.add_artist(at) at.txt._text.set_path_effects([withStroke(foreground="w", linewidth=3)]) return at
Example #8
Source File: seisegy.py From pyGeoPressure with MIT License | 5 votes |
def _(self, index, ax, kind='vawt', cm='seismic', ptype='seis'): data = self.data(index) handle = None if kind == 'vawt': wiggles(data.T, wiggleInterval=1, ax=ax) elif kind == 'img': handle = img(data.T, extent=[ self.startCrline, self.endCrline, self.startDepth, self.endDepth], ax=ax, cm=cm, ptype=ptype) ax.invert_yaxis() else: pass ax.get_figure().suptitle('In-line Section: {}'.format(index.value)) from matplotlib.offsetbox import AnchoredText z_text = AnchoredText( r"$\downarrow$Z", loc=2, prop=dict(size=10), frameon=False, bbox_to_anchor=(0., 0.), bbox_transform=ax.transAxes) ax.add_artist(z_text) inline_text = AnchoredText( r"Cross-line $\rightarrow$ ", loc=1, prop=dict(size=10), frameon=False, bbox_to_anchor=(1., 0.), bbox_transform=ax.transAxes) ax.add_artist(inline_text) return handle
Example #9
Source File: seisegy.py From pyGeoPressure with MIT License | 5 votes |
def _(self, index, ax, kind='vawt', cm='seismic', ptype='seis'): data = self.data(index) handle = None if kind == 'vawt': wiggles(data.T, wiggleInterval=1, ax=ax) elif kind == 'img': handle = img(data.T, extent=[ self.startInline, self.endInline, self.startDepth, self.endDepth], ax=ax, cm=cm, ptype=ptype) ax.invert_yaxis() else: pass ax.get_figure().suptitle('Cross-line Section: {}'.format(index.value)) from matplotlib.offsetbox import AnchoredText z_text = AnchoredText( r"$\downarrow$Z", loc=2, prop=dict(size=10), frameon=False, bbox_to_anchor=(0., 0.), bbox_transform=ax.transAxes) ax.add_artist(z_text) inline_text = AnchoredText( r"In-line $\rightarrow$ ", loc=1, prop=dict(size=10), frameon=False, bbox_to_anchor=(1., 0.), bbox_transform=ax.transAxes) ax.add_artist(inline_text) return handle
Example #10
Source File: seisegy.py From pyGeoPressure with MIT License | 5 votes |
def _(self, index, ax, kind='vawt', cm='seismic', ptype='seis'): data = self.data(index) handle = None if kind == 'vawt': wiggles(data.T, wiggleInterval=1, ax=ax) elif kind == 'img': handle = img(data.T, extent=[ self.startInline, self.endInline, self.startCrline, self.endCrline,], ax=ax, cm=cm, ptype=ptype) ax.invert_yaxis() else: pass ax.get_figure().suptitle("Z slice: {}".format(index.value)) from matplotlib.offsetbox import AnchoredText z_text = AnchoredText( r"$\downarrow$Cross-line", loc=2, prop=dict(size=10), frameon=False, bbox_to_anchor=(0., 0.), bbox_transform=ax.transAxes) ax.add_artist(z_text) inline_text = AnchoredText( r"In-line $\rightarrow$ ", loc=1, prop=dict(size=10), frameon=False, bbox_to_anchor=(1., 0.), bbox_transform=ax.transAxes) ax.add_artist(inline_text) return handle
Example #11
Source File: display.py From jams with ISC License | 4 votes |
def display(annotation, meta=True, **kwargs): '''Visualize a jams annotation through mir_eval Parameters ---------- annotation : jams.Annotation The annotation to display meta : bool If `True`, include annotation metadata in the figure kwargs Additional keyword arguments to mir_eval.display functions Returns ------- ax Axis handles for the new display Raises ------ NamespaceError If the annotation cannot be visualized ''' for namespace, func in six.iteritems(VIZ_MAPPING): try: ann = coerce_annotation(annotation, namespace) axes = func(ann, **kwargs) # Title should correspond to original namespace, not the coerced version axes.set_title(annotation.namespace) if meta: description = pprint_jobject(annotation.annotation_metadata, indent=2) anchored_box = AnchoredText(description.strip('\n'), loc=2, frameon=True, bbox_to_anchor=(1.02, 1.0), bbox_transform=axes.transAxes, borderpad=0.0) axes.add_artist(anchored_box) axes.figure.subplots_adjust(right=0.8) return axes except NamespaceError: pass raise NamespaceError('Unable to visualize annotation of namespace="{:s}"' .format(annotation.namespace))