Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

text - Matplotlib custom bbox style with Underline + Facecolor possible?

Is it possible to define custom matpotlib boxstyles that look like these, eg. with a thick underline and a facecolor?

html text style example 1
html text style example 2

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...