Is it possible to define custom matpotlib boxstyles that look like these, eg. with a thick underline and a facecolor?
images from https://academy.datawrapper.de/article/190-how-to-turn-your-title-into-a-color-key
I managed the underline but if I only have this line as the returned path, facecolor won't have an effect.
Is it possible to return two combined paths for example?
import matplotlib.pyplot as plt
from matplotlib.patches import BoxStyle
from matplotlib.path import Path
def underline(x0, y0, width, height, mutation_size, mutation_aspect=1, pad=0.3):
"""
Given the location and size of the box, return the path of the box around
it.
Rotation is automatically taken care of.
Parameters
----------
x0, y0, width, height : float
Box location and size.
mutation_size : float
Mutation reference scale, typically the text font size.
mutation_aspect
Mutation aspect ratio.
"""
# We ignore mutation_aspect. This is okay in general.
x1 = x0 + width
# return the new path
return Path([(x0, y0),
(x1, y0)],
closed=False)
fig, ax = plt.subplots(figsize=(3, 3))
ax.text(0.5, 0.5, "Test", size=30, va="center", ha="center",
bbox=dict(boxstyle=underline))
question from:
https://stackoverflow.com/questions/65922300/matplotlib-custom-bbox-style-with-underline-facecolor-possible 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…