Skip to content

Commit 29f8c02

Browse files
authored
Merge pull request #240 from pratiman-91/master
Permit setting style='default', add 'bbox' as 'border' alternative for titles/a-b-c labels
2 parents 7a8e965 + 35df66d commit 29f8c02

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed

proplot/axes/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,11 @@ def format(
822822
positioned inside the axes. This can help them stand out on top
823823
of artists plotted inside the axes. Defaults are
824824
:rc:`abc.border` and :rc:`title.border`
825+
abcbbox, titlebbox : bool, optional
826+
Whether to draw a white bbox around titles and a-b-c labels
827+
positioned inside the axes. This can help them stand out on top
828+
of artists plotted inside the axes. Defaults are
829+
:rc:`abc.bbox` and :rc:`title.bbox`
825830
titlepad : float, optional
826831
The padding for the inner and outer titles and a-b-c labels in
827832
arbitrary units (default is points). Default is :rc:`axes.titlepad`.
@@ -927,6 +932,10 @@ def sanitize_kw(kw, loc):
927932
if loc in ('left', 'right', 'center'):
928933
kw.pop('border', None)
929934
kw.pop('borderwidth', None)
935+
kw.pop('bbox', None)
936+
kw.pop('bboxcolor', None)
937+
kw.pop('bboxstyle', None)
938+
kw.pop('bboxalpha', None)
930939
return kw
931940

932941
# A-b-c labels
@@ -949,6 +958,10 @@ def sanitize_kw(kw, loc):
949958
{
950959
'border': 'abc.border',
951960
'borderwidth': 'abc.borderwidth',
961+
'bbox': 'abc.bbox',
962+
'bboxcolor': 'abc.bboxcolor',
963+
'bboxstyle': 'abc.bboxstyle',
964+
'bboxalpha': 'abc.bboxalpha',
952965
},
953966
context=True,
954967
)
@@ -1011,6 +1024,10 @@ def sanitize_kw(kw, loc):
10111024
{
10121025
'border': 'title.border',
10131026
'borderwidth': 'title.borderwidth',
1027+
'bbox': 'title.bbox',
1028+
'bboxcolor': 'title.bboxcolor',
1029+
'bboxstyle': 'title.bboxstyle',
1030+
'bboxalpha': 'title.bboxalpha',
10141031
},
10151032
context=True,
10161033
)

proplot/axes/plot.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ def _get_transform(self, transform):
21792179

21802180
def _update_text(self, props):
21812181
"""
2182-
Monkey patch that adds pseudo "border" properties to text objects
2182+
Monkey patch that adds pseudo "border" and "bbox" properties to text objects
21832183
without wrapping the entire class. We override update to facilitate
21842184
updating inset titles.
21852185
"""
@@ -2201,6 +2201,20 @@ def _update_text(self, props):
22012201
'color': facecolor,
22022202
'path_effects': [mpatheffects.Stroke(**kwargs), mpatheffects.Normal()],
22032203
})
2204+
2205+
bbox = props.pop('bbox', None)
2206+
bboxcolor = props.pop('bboxcolor', 'w')
2207+
bboxstyle = props.pop('bboxstyle', 'round')
2208+
bboxalpha = props.pop('bboxalpha', 0.5)
2209+
2210+
if bbox:
2211+
self.set_bbox({
2212+
'facecolor': bboxcolor,
2213+
'edgecolor': 'black',
2214+
'boxstyle': bboxstyle,
2215+
'alpha': bboxalpha,
2216+
})
2217+
22042218
return type(self).update(self, props)
22052219

22062220

@@ -2209,11 +2223,12 @@ def text_wrapper(
22092223
x=0, y=0, text='', transform='data',
22102224
family=None, fontfamily=None, fontname=None, fontsize=None, size=None,
22112225
border=False, bordercolor='w', borderwidth=2, borderinvert=False,
2226+
bbox=False, bboxcolor='w', bboxstyle='round', bboxalpha=0.5,
22122227
**kwargs
22132228
):
22142229
"""
22152230
Enables specifying `tranform` with a string name and adds a feature for
2216-
drawing borders around text.
2231+
drawing borders and bbox around text.
22172232
22182233
Note
22192234
----
@@ -2248,7 +2263,14 @@ def text_wrapper(
22482263
The color of the text border. Default is ``'w'``.
22492264
borderinvert : bool, optional
22502265
If ``True``, the text and border colors are swapped.
2251-
2266+
bbox : bool, optional
2267+
Whether to draw bbox around text.
2268+
bboxcolor : color-spec, optional
2269+
The color of the text bbox. Default is ``'w'``.
2270+
bboxstyle : boxstyle, optional
2271+
The style of the bbox. Default is ``'round'``.
2272+
bboxalpha : float, optional
2273+
The alpha for the bbox. Default is ``'0.5'``.
22522274
Other parameters
22532275
----------------
22542276
**kwargs
@@ -2287,6 +2309,10 @@ def text_wrapper(
22872309
'bordercolor': bordercolor,
22882310
'borderinvert': borderinvert,
22892311
'borderwidth': borderwidth,
2312+
'bbox': bbox,
2313+
'bboxcolor': bboxcolor,
2314+
'bboxstyle': bboxstyle,
2315+
'bboxalpha': bboxalpha,
22902316
})
22912317
return obj
22922318

proplot/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,11 @@ def _get_style_dicts(style, infer=False, filter=True):
11581158
# Always apply the default style *first* so styles are rigid
11591159
kw_matplotlib = _get_default_dict()
11601160
if style == 'default' or style is mpl.rcParamsDefault:
1161-
return kw_matplotlib
1161+
if infer:
1162+
kw_proplot = _infer_added_params(kw_matplotlib)
1163+
return kw_matplotlib, kw_proplot
1164+
else:
1165+
return kw_matplotlib
11621166

11631167
# Apply limited deviations from the matplotlib style that we want to propagate to
11641168
# other styles. Want users selecting stylesheets to have few surprises, so

proplot/internals/rcsetup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,22 @@
266266
1.5,
267267
'Width of the white border around a-b-c labels.'
268268
),
269+
'abc.bbox': (
270+
True,
271+
'Boolean, whether to draw semi-transparent bbox around the a-b-c.'
272+
),
273+
'abc.bboxcolor': (
274+
'w',
275+
'color-spec, the color of the a-b-c bbox.'
276+
),
277+
'abc.bboxstyle': (
278+
'round',
279+
'boxstyle, the style of the a-b-c bbox.'
280+
),
281+
'abc.bboxalpha': (
282+
0.5,
283+
'float, The alpha for the a-b-c bbox.'
284+
),
269285
'abc.color': (
270286
'black',
271287
'a-b-c label color.'
@@ -862,6 +878,23 @@
862878
1.5,
863879
'Width of the white border around titles.'
864880
),
881+
'title.bbox': (
882+
True,
883+
'Boolean, whether to draw semi-transparent bbox around the title.'
884+
'when :rcraw:`title.loc` is inside the axes.'
885+
),
886+
'title.bboxcolor': (
887+
'w',
888+
'color-spec, the color of the title bbox.'
889+
),
890+
'title.bboxstyle': (
891+
'round',
892+
'boxstyle, the style of the title bbox.'
893+
),
894+
'title.bboxalpha': (
895+
0.5,
896+
'float, The alpha for the title bbox.'
897+
),
865898
'title.color': (
866899
'black',
867900
'Axes title color.'

0 commit comments

Comments
 (0)