8000 Anchored sizebar fontprop by pelson · Pull Request #2712 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Anchored sizebar fontprop #2712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 13, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add fontprop parameter to anchored_artists.AnchoredSizeBar
Removed the old fontsize parameter.
And fix: some typos in the example in the docstring
  • Loading branch information
magnunor authored and pelson committed Jan 9, 2014
commit a693d000463dea7a9decc6a6d6d6711e15a6934c
41 changes: 28 additions & 13 deletions lib/mpl_toolkits/axes_grid1/anchored_artists.py
< 7F44 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class AnchoredSizeBar(AnchoredOffsetbox):
def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2, prop=None,
frameon=True, size_vertical=0, color='black',
label_top=False, fontsize=12,
label_top=False, fontprops=None,
**kwargs):
"""
Draw a horizontal bar with the size in data coordinate of the give axes.
Draw a horizontal bar with the size in data coordinate of the given axes.
A label will be drawn underneath (center-aligned).

Parameters:
Expand All @@ -98,29 +98,44 @@ def __init__(self, transform, size, label, loc,
color for the size bar and label
label_top : bool, optional
if True, the label will be over the rectangle
fontsize : int, optional
sets the fontsize for the label
fontprops: a matplotlib.font_manager.FontProperties instance, optional
sets the font properties for the label text

Returns:
--------
AnchoredSizeBar object

Example:
--------
>>>> import matplotlib.pyplot as plt
>>>> import numpy as np
>>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
>>>> fig, ax = plt.subplots()
>>>> ax = imshow(np.random.random((10,10)))
>>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', pad=0.5, loc=4, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontsize=20)
>>>> ax.add_artist(bar)
>>>> fig.show()
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
>>> fig, ax = plt.subplots()
>>> ax.imshow(np.random.random((10,10)))
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4)
>>> ax.add_artist(bar)
>>> fig.show()

Using all the optional parameters

>>> import matplotlib.font_manager as fm
>>> fontprops = fm.FontProperties(size=14, family='monospace')
>>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5, sep=5, borderpad=0.5, frameon=False, size_vertical=0.5, color='white', fontprops=fontprops)

"""

self.size_bar = AuxTransformBox(transform)
self.size_bar.add_artist(Rectangle((0,0), size, size_vertical, fill=True, facecolor=color, edgecolor=color))

if not fontprops:
textprops = {'color': color}
else:
textprops = {'color': color, 'fontproperties': fontprops}

self.txt_label = TextArea(
label,
minimumdescent=False,
textprops=dict(color=color, fontsize=fontsize))
textprops=textprops)

if label_top:
_box_children = [self.txt_label, self.size_bar]
Expand Down
0