@@ -326,7 +326,8 @@ def plot_homline(
326326 return handles
327327
328328 def plot_box (
329- * fmt : Optional [str ],
329+ fmt : str | None = None ,
330+ * ,
330331 lbrt : Optional [ArrayLike4 ] = None ,
331332 lrbt : Optional [ArrayLike4 ] = None ,
332333 lbwh : Optional [ArrayLike4 ] = None ,
@@ -338,6 +339,7 @@ def plot_box(
338339 rt : Optional [ArrayLike2 ] = None ,
339340 wh : Optional [ArrayLike2 ] = None ,
340341 centre : Optional [ArrayLike2 ] = None ,
342+ center : Optional [ArrayLike2 ] = None ,
341343 w : Optional [float ] = None ,
342344 h : Optional [float ] = None ,
343345 ax : Optional [plt .Axes ] = None ,
@@ -357,39 +359,79 @@ def plot_box(
357359 :type rt: array_like(2), optional
358360 :param wh: width and height, if both are the same provide scalar, defaults to None
359361 :type wh: scalar, array_like(2), optional
360- :param centre: centre of box, defaults to None
362+ :param centre: centre of box, defaults to None (alias: ``center``)
361363 :type centre: array_like(2), optional
362364 :param w: width of box, defaults to None
363365 :type w: float, optional
364366 :param h: height of box, defaults to None
365367 :type h: float, optional
368+ ;param lbrt: left-bottom, right-top corners, defaults to None
369+ :type lbrt: array_like(4), optional
370+ :param lrbt: left-right, bottom-top corners, defaults to None
371+ :type lrbt: array_like(4), optional
372+ :param lbwh: left-bottom corner, width and height, defaults to None
373+ :type lbwh: array_like(4), optional
374+ :param ltrb: left-top, right-bottom corners, defaults to None
375+ :type ltrb: array_like(4), optional
366376 :param ax: the axes to draw on, defaults to ``gca()``
367377 :type ax: Axis, optional
368378 :param bbox: bounding box matrix, defaults to None
369379 :type bbox: array_like(4), optional
370- :param color: box outline color
380+ :param filled: fill the box, defaults to False (alias for Matplotlib ``fill``)
381+ :type filled: bool
382+ :param thickness: line thickness (alias for Matplotlib ``linewidth``)
383+ :type thickness: float, optional
384+ :param kwargs: additional arguments passed to ``pyplot.Rectangle()``
385+
386+ :return: the matplotlib object
387+ :rtype: Patch.Rectangle instance
388+
389+ Appearance is controlled by Matplotlib properties passed as keyword arguments, for example:
390+
391+ :param color: box outline and fill color
371392 :type color: array_like(3) or str
372- :param fillcolor: box fill color
393+ :param edgecolor: box outline colour (alias: ``ec``)
394+ :type edgecolor: array_like(3) or str
395+ :param fillcolor: box fill colour
373396 :type fillcolor: array_like(3) or str
397+ :param filled: fill the box, defaults to False
398+ :type filled: bool
374399 :param alpha: transparency, defaults to 1
375400 :type alpha: float, optional
376- :param thickness: line thickness, defaults to None
377- :type thickness: float, optional
378- :return: the matplotlib object
379- :rtype: Patch.Rectangle instance
401+ :param linestyle: box outline line style (alias: ``ls``)
402+ :type linestyle: str, optional
403+ :param linewidth: box outline line thickness (alias: ``lw``)
404+ :type linewidth: float, optional
405+
406+ Additionally, the line style and color can be conveniently set using the pyplot
407+ convention where the first argument is a ``fmt`` string, for example ``"r--"``
408+ for dashed red. The allowable color letters are ``"rgbcmyk"`` and the line style
409+ characters are ``"-", "--", "-.", ":"``.
410+
411+ The box can be specified in many ways. Two corners:
380412
381- The box can be specified in many ways:
413+ - `lb` = left-bottom corner
414+ - `lt` = left-top corner
415+ - `rb` = right-bottom corner
416+ - `rt` = right-top corner
382417
383- - bounding box [xmin, xmax, ymin, ymax]
384- - alternative box [xmin, ymin, xmax, ymax]
385- - centre and width+height
386- - left-bottom and right-top corners
387- - left-bottom corner and width+height
388- - right-top corner and width+height
389- - left-top corner and width+height
418+ Alternatively, one corner or `centre` plus the dimensons:
419+
420+ - `wh` = [width, height]
421+ - `w` = width
422+ - `h` = height
423+
424+ Alternatively, the box can be specified by a number of 4-vectors, various
425+ conventions are in use across different packages, so we support them all:
426+
427+ - `lbrt` = [umin, vmin, umax, vmax]
428+ - `lrbt` = [umin, umax, vmin, vmax]
429+ - `lbwh` = [umin, vmin, w, h]
430+ - `bbox` same as `lbwh`
431+ - `ltrb` = [umin, vmin, umax, vmax]`
390432
391433 For plots where the y-axis is inverted (eg. for images) then top is the
392- smaller vertical coordinate.
434+ smaller vertical coordinate (highest in the window) .
393435
394436 Example::
395437
@@ -439,6 +481,8 @@ def plot_box(
439481 elif w is not None and h is not None :
440482 # we have width & height, one corner is enough
441483
484+ if centre is None :
485+ centre = center
442486 if centre is not None :
443487 lb = (centre [0 ] - w / 2 , centre [1 ] - h / 2 )
444488
@@ -463,7 +507,7 @@ def plot_box(
463507 h = lt [1 ] - rb [1 ]
464508
465509 else :
466- raise ValueError ("cant compute box" )
510+ raise ValueError ("insufficient parameters to compute a box" )
467511
468512 if w < 0 :
469513 raise ValueError ("width must be positive" )
@@ -478,9 +522,9 @@ def plot_box(
478522 else :
479523 ec = None
480524 ls = ""
481- if len ( fmt ) > 0 :
525+ if fmt is not None :
482526 colors = "rgbcmywk"
483- for f in fmt [ 0 ] :
527+ for f in fmt :
484528 if f in colors :
485529 ec = f
486530 else :
@@ -489,8 +533,13 @@ def plot_box(
489533 ls = None
490534
491535 if "color" in kwargs :
492- ec = kwargs ["color" ]
493- del kwargs ["color" ]
536+ ec = kwargs .pop ("color" )
537+ if "edgecolor" in kwargs :
538+ ec = kwargs .pop ("edgecolor" )
539+ if "linestyle" in kwargs :
540+ ls = kwargs .pop ("linestyle" )
541+ elif "ls" in kwargs :
542+ ls = kwargs .pop ("ls" )
494543 r = plt .Rectangle (
495544 lb , w , h , clip_on = True , linestyle = ls , edgecolor = ec , fill = False , ** kwargs
496545 )
@@ -557,7 +606,7 @@ def plot_arrow(
557606 ax = plotvol2(5)
558607 ax.grid()
559608 plot_arrow(
560- (-2, -2), (2, 4), label="$\mathit{p}_3$", color="r", width=0.1
609+ (-2, -2), (2, 4), label=r "$\mathit{p}_3$", color="r", width=0.1
561610 )
562611 plt.show(block=True)
563612
0 commit comments