Skip to content

Commit 4288a73

Browse files
committed
Bbox off by default, flush when on, turns off border (improves #240)
1 parent 1ac8cda commit 4288a73

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

WHATSNEW.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ProPlot v0.8.0 (2021-##-##)
6161

6262
.. rubric:: Internals
6363

64-
* Assignments to `~proplot.rctools.rc_configurator` are now validated, and
64+
* Assignments to `~proplot.config.RcConfigurator` are now validated, and
6565
the configurator is now a monkey patch of `~matplotlib.rcParams`
6666
(:pr:`109`).
6767
* Plotting wrapper features (e.g. `~proplot.wrappers.standardize_1d`) are now
@@ -103,6 +103,7 @@ ProPlot v0.7.0 (2021-06-30)
103103
by `Mickaël Lalande`_.
104104
* Add `titlebbox` and `abcbbox` as alternatives to `titleborder` and `abcborder`
105105
for "inner" titles and a-b-c labels (:pr:`240`) by `Pratiman Patel`_.
106+
Default behavior uses borders.
106107
* Add `nozero` keyword arg to `cmap_changer` to remove the zero contour
107108
from automatically generated levels (:commit:`10e0f13b`).
108109
Example usage: ``ax.contour(x, y, z, nozero=True)``.
@@ -358,6 +359,8 @@ ProPlot v0.6.0 (2020-05-20)
358359
degree-shifted colormap, similar to ``'cmap_r'`` (:commit:`da4ccb08`).
359360
* Rename ``GrayCycle`` colormap to ``MonoCycle`` to more accurately reflect
360361
colormap design origins (:commit:`d67e45bf`).
362+
* Rename `~proplot.config.rc_configurator` to `~proplot.config.RcConfigurator`
363+
to match capitalized class naming convention.
361364
* Rename `~proplot.colors.MidpointNorm` to more intuitive
362365
`~proplot.colors.DivergingNorm`, and make "fair" color scaling the default
363366
behavior (:commit:`2f549c9`).
@@ -395,8 +398,8 @@ ProPlot v0.6.0 (2020-05-20)
395398
used for minor gridlines is `~matplotlib.ticker.AutoMinorLocator`.
396399
* Add `loninline`, `latinline`, and `rotatelabels` keywords for controlling
397400
cartopy gridliner behavior (:pr:`168`).
398-
* Add `proplot.config.rc_configurator.save` and
399-
`proplot.config.rc_configurator.from_file` methods (:pr:`167`, :commit:`e6dd8314`).
401+
* Add `proplot.config.RcConfigurator.save` and
402+
`proplot.config.RcConfigurator.from_file` methods (:pr:`167`, :commit:`e6dd8314`).
400403
* Increase default :rcraw:`savefig.dpi` to 1200, matching recommendations
401404
from academic journals (:pr:`167`, :commit:`c00e7314`). Also add detailed discussion
402405
to user guide.
@@ -483,7 +486,7 @@ ProPlot v0.6.0 (2020-05-20)
483486
* Fix deprecation of direct access to ``matplotlib.cm.cmap_d``
484487
in matplotlib >=3.2.0 (:pr:`149`, :commit:`a69c16da`).
485488
* Fix issues with string font sizes (:pr:`149`, :commit:`6121de03`). Add hidden
486-
`~proplot.config.rc_configurator._get_font_size` method to
489+
`~proplot.config.RcConfigurator._get_font_size` method to
487490
translate font size to numeric.
488491
* Fix issue where passing actual projection instances generated with
489492
`~proplot.constructor.Proj` to `~proplot.ui.subplots` could incorrectly

proplot/axes/plot.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,8 @@ def _update_text(self, props):
21842184
updating inset titles.
21852185
"""
21862186
props = props.copy() # shallow copy
2187+
2188+
# Update border
21872189
border = props.pop('border', None)
21882190
bordercolor = props.pop('bordercolor', 'w')
21892191
borderinvert = props.pop('borderinvert', False)
@@ -2202,17 +2204,21 @@ def _update_text(self, props):
22022204
'path_effects': [mpatheffects.Stroke(**kwargs), mpatheffects.Normal()],
22032205
})
22042206

2207+
# Update bounding box
2208+
# NOTE: For some reason using pad / 10 results in perfect alignment. Matplotlib
2209+
# docs are vague about bounding box units, maybe they are tens of points?
22052210
bbox = props.pop('bbox', None)
22062211
bboxcolor = props.pop('bboxcolor', 'w')
22072212
bboxstyle = props.pop('bboxstyle', 'round')
22082213
bboxalpha = props.pop('bboxalpha', 0.5)
2209-
2214+
bboxpad = _not_none(props.pop('bboxpad', None), self.axes._title_pad / 10)
22102215
if bbox:
22112216
self.set_bbox({
2212-
'facecolor': bboxcolor,
22132217
'edgecolor': 'black',
2218+
'facecolor': bboxcolor,
22142219
'boxstyle': bboxstyle,
22152220
'alpha': bboxalpha,
2221+
'pad': bboxpad,
22162222
})
22172223

22182224
return type(self).update(self, props)
@@ -2223,7 +2229,7 @@ def text_wrapper(
22232229
x=0, y=0, text='', transform='data',
22242230
family=None, fontfamily=None, fontname=None, fontsize=None, size=None,
22252231
border=False, bordercolor='w', borderwidth=2, borderinvert=False,
2226-
bbox=False, bboxcolor='w', bboxstyle='round', bboxalpha=0.5,
2232+
bbox=False, bboxcolor='w', bboxstyle='round', bboxalpha=0.5, bboxpad=None,
22272233
**kwargs
22282234
):
22292235
"""
@@ -2264,13 +2270,16 @@ def text_wrapper(
22642270
borderinvert : bool, optional
22652271
If ``True``, the text and border colors are swapped.
22662272
bbox : bool, optional
2267-
Whether to draw bbox around text.
2273+
Whether to draw a bouning box around text.
22682274
bboxcolor : color-spec, optional
2269-
The color of the text bbox. Default is ``'w'``.
2275+
The color of the text bouning box. Default is ``'w'``.
22702276
bboxstyle : boxstyle, optional
2271-
The style of the bbox. Default is ``'round'``.
2277+
The style of the bouning box. Default is ``'round'``.
22722278
bboxalpha : float, optional
2273-
The alpha for the bbox. Default is ``'0.5'``.
2279+
The alpha for the bounding box. Default is ``'0.5'``.
2280+
bboxpad : float, optional
2281+
The padding of the bounding box. Default is :rc:`title.pad` / 10.
2282+
22742283
Other parameters
22752284
----------------
22762285
**kwargs
@@ -2313,6 +2322,7 @@ def text_wrapper(
23132322
'bboxcolor': bboxcolor,
23142323
'bboxstyle': bboxstyle,
23152324
'bboxalpha': bboxalpha,
2325+
'bboxpad': bboxpad,
23162326
})
23172327
return obj
23182328

proplot/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ def _get_synced_params(self, key, value):
419419
kw_proplot.update(ikw_proplot)
420420
kw_matplotlib.update(ikw_matplotlib)
421421

422+
# Turning bounding box on should turn border off and vice versa
423+
elif key in ('abc.bbox', 'title.bbox', 'abc.border', 'title.border'):
424+
if value:
425+
name, this = key.split('.')
426+
other = 'border' if this == 'bbox' else 'border'
427+
kw_proplot[name + '.' + other] = False
428+
422429
# Tick length/major-minor tick length ratio
423430
elif key in ('tick.len', 'tick.lenratio'):
424431
if key == 'tick.len':

proplot/internals/rcsetup.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,24 @@
267267
'Width of the white border around a-b-c labels.'
268268
),
269269
'abc.bbox': (
270-
True,
270+
False,
271271
'Boolean, whether to draw semi-transparent bbox around the a-b-c.'
272272
),
273273
'abc.bboxcolor': (
274274
'w',
275-
'color-spec, the color of the a-b-c bbox.'
275+
'Color-spec, the color of the a-b-c bbox.'
276276
),
277277
'abc.bboxstyle': (
278-
'round',
279-
'boxstyle, the style of the a-b-c bbox.'
278+
'square',
279+
'Box style, the style of the a-b-c bbox.'
280280
),
281281
'abc.bboxalpha': (
282282
0.5,
283-
'float, The alpha for the a-b-c bbox.'
283+
'Float, the alpha for the a-b-c bbox.'
284+
),
285+
'abc.bboxpad': (
286+
None,
287+
'Float, the alpha for the a-b-c bbox.'
284288
),
285289
'abc.color': (
286290
'black',
@@ -879,21 +883,25 @@
879883
'Width of the white border around titles.'
880884
),
881885
'title.bbox': (
882-
True,
886+
False,
883887
'Boolean, whether to draw semi-transparent bbox around the title.'
884888
'when :rcraw:`title.loc` is inside the axes.'
885889
),
886890
'title.bboxcolor': (
887891
'w',
888-
'color-spec, the color of the title bbox.'
892+
'Color-spec, the color of the a-b-c bbox.'
889893
),
890894
'title.bboxstyle': (
891-
'round',
892-
'boxstyle, the style of the title bbox.'
895+
'square',
896+
'Box style, the style of the a-b-c bbox.'
893897
),
894898
'title.bboxalpha': (
895899
0.5,
896-
'float, The alpha for the title bbox.'
900+
'Float, the alpha for the a-b-c bbox.'
901+
),
902+
'title.bboxpad': (
903+
None,
904+
'Float, the alpha for the a-b-c bbox.'
897905
),
898906
'title.color': (
899907
'black',

0 commit comments

Comments
 (0)