Skip to content

Commit 2b7effd

Browse files
committed
bbox implemtation in the internal abc and titles
1 parent e9ee7c5 commit 2b7effd

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

proplot/axes/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ def format(
809809
positioned inside the axes. This can help them stand out on top
810810
of artists plotted inside the axes. Defaults are
811811
:rc:`abc.border` and :rc:`title.border`
812+
abcbbox, titlebbox : bool, optional
813+
Whether to draw a white bbox around titles and a-b-c labels
814+
positioned inside the axes. This can help them stand out on top
815+
of artists plotted inside the axes. Defaults are
816+
:rc:`abc.bbox` and :rc:`title.bbox`
812817
abovetop : bool, optional
813818
Whether to try to put the title and a-b-c label above the top panel
814819
(if it exists), or to always put them above the main subplot.
@@ -921,6 +926,10 @@ def sanitize_kw(kw, loc):
921926
if loc in ('left', 'right', 'center'):
922927
kw.pop('border', None)
923928
kw.pop('borderwidth', None)
929+
kw.pop('bbox', None)
930+
kw.pop('bboxcolor', None)
931+
kw.pop('bboxstyle', None)
932+
kw.pop('bboxalpha', None)
924933
return kw
925934

926935
# A-b-c labels
@@ -943,6 +952,10 @@ def sanitize_kw(kw, loc):
943952
{
944953
'border': 'abc.border',
945954
'borderwidth': 'abc.borderwidth',
955+
'bbox': 'abc.bbox',
956+
'bboxcolor': 'abc.bboxcolor',
957+
'bboxstyle': 'abc.bboxstyle',
958+
'bboxalpha': 'abc.bboxalpha',
946959
},
947960
context=True,
948961
)
@@ -1009,6 +1022,10 @@ def sanitize_kw(kw, loc):
10091022
{
10101023
'border': 'title.border',
10111024
'borderwidth': 'title.borderwidth',
1025+
'bbox': 'title.bbox',
1026+
'bboxcolor': 'title.bboxcolor',
1027+
'bboxstyle': 'title.bboxstyle',
1028+
'bboxalpha': 'title.bboxalpha',
10121029
},
10131030
context=True,
10141031
)

proplot/axes/plot.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ def _get_transform(self, transform):
21692169

21702170
def _update_text(self, props):
21712171
"""
2172-
Monkey patch that adds pseudo "border" properties to text objects
2172+
Monkey patch that adds pseudo "border" and "bbox" properties to text objects
21732173
without wrapping the entire class. We override update to facilitate
21742174
updating inset titles.
21752175
"""
@@ -2191,6 +2191,18 @@ def _update_text(self, props):
21912191
'color': facecolor,
21922192
'path_effects': [mpatheffects.Stroke(**kwargs), mpatheffects.Normal()],
21932193
})
2194+
2195+
bbox = props.pop('bbox', None)
2196+
bboxcolor = props.pop('bboxcolor', 'w')
2197+
bboxstyle = props.pop('bboxstyle', 'round')
2198+
bboxalpha = props.pop('bboxalpha', 0.5)
2199+
2200+
if bbox:
2201+
self.set_bbox(dict(facecolor=bboxcolor,
2202+
edgecolor='black',
2203+
boxstyle=bboxstyle,
2204+
alpha=bboxalpha))
2205+
21942206
return type(self).update(self, props)
21952207

21962208

@@ -2199,11 +2211,12 @@ def text_wrapper(
21992211
x=0, y=0, text='', transform='data',
22002212
family=None, fontfamily=None, fontname=None, fontsize=None, size=None,
22012213
border=False, bordercolor='w', borderwidth=2, borderinvert=False,
2214+
bbox=False, bboxcolor='w', bboxstyle='round', bboxalpha=0.5,
22022215
**kwargs
22032216
):
22042217
"""
22052218
Enables specifying `tranform` with a string name and adds a feature for
2206-
drawing borders around text.
2219+
drawing borders and bbox around text.
22072220
22082221
Note
22092222
----
@@ -2238,7 +2251,14 @@ def text_wrapper(
22382251
The color of the text border. Default is ``'w'``.
22392252
borderinvert : bool, optional
22402253
If ``True``, the text and border colors are swapped.
2241-
2254+
bbox : bool, optional
2255+
Whether to draw bbox around text.
2256+
bboxcolor : color-spec, optional
2257+
The color of the text bbox. Default is ``'w'``.
2258+
bboxstyle : boxstyle, optional
2259+
The style of the bbox. Default is ``'round'``.
2260+
bboxalpha : float, optional
2261+
The alpha for the bbox. Default is ``'0.5'``.
22422262
Other parameters
22432263
----------------
22442264
**kwargs
@@ -2277,6 +2297,10 @@ def text_wrapper(
22772297
'bordercolor': bordercolor,
22782298
'borderinvert': borderinvert,
22792299
'borderwidth': borderwidth,
2300+
'bbox' : bbox,
2301+
'bboxcolor': bboxcolor,
2302+
'bboxstyle' : bboxstyle,
2303+
'bboxalpha' : bboxalpha,
22802304
})
22812305
return obj
22822306

proplot/internals/rcsetup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@
265265
1.5,
266266
'Width of the white border around a-b-c labels.'
267267
),
268+
'abc.bbox': (
269+
True,
270+
'Boolean, whether to draw semi-transparent bbox around the a-b-c.'
271+
),
272+
'abc.bboxcolor': (
273+
'w',
274+
'color-spec, the color of the a-b-c bbox.'
275+
),
276+
'abc.bboxstyle': (
277+
'round',
278+
'boxstyle, the style of the a-b-c bbox.'
279+
),
280+
'abc.bboxalpha': (
281+
0.5,
282+
'float, The alpha for the a-b-c bbox.'
283+
),
268284
'abc.color': (
269285
'black',
270286
'a-b-c label color.'
@@ -851,6 +867,23 @@
851867
1.5,
852868
'Width of the white border around titles.'
853869
),
870+
'title.bbox': (
871+
True,
872+
'Boolean, whether to draw semi-transparent bbox around the title.'
873+
'when :rcraw:`title.loc` is inside the axes.'
874+
),
875+
'title.bboxcolor': (
876+
'w',
877+
'color-spec, the color of the title bbox.'
878+
),
879+
'title.bboxstyle': (
880+
'round',
881+
'boxstyle, the style of the title bbox.'
882+
),
883+
'title.bboxalpha': (
884+
0.5,
885+
'float, The alpha for the title bbox.'
886+
),
854887
'title.color': (
855888
'black',
856889
'Axes title color.'

0 commit comments

Comments
 (0)