【问题标题】:custom marker with lines skipping the marker region带有跳过标记区域的行的自定义标记
【发布时间】:2021-02-06 20:42:44
【问题描述】:

我们可以根据自定义标记

import matplotlib as mpl
mpl.rcParams['text.usetex'] = True # enable latex support
mpl.style.use('fivethirtyeight')   # gray background

import matplotlib.pyplot as plt

plt.plot(
    range(0,10,2),
    range(0,10,2),
    marker="$abc$",
    markersize=30
)

给了

我们如何让线条跳过每个自定义标记后面的区域?

(无需手动添加/减去各个点)

【问题讨论】:

    标签: python matplotlib line markers


    【解决方案1】:

    您可以使用第二个带有白色填充物的记号笔。

    import matplotlib.pyplot as plt
    
    plt.plot(
        range(0,10,2),
        range(0,10,2),
        marker="o",
        markersize=30,
        markerfacecolor = 'white',
        markeredgecolor = 'white',
        color = 'blue'
    )
    plt.plot(
        range(0,10,2),
        range(0,10,2),
        marker="$abc$",
        markersize=30,
        linestyle = 'none',
        color = 'blue'
    )
    

    编辑:但这不适用于自定义背景。 为此,您可以将markeredgewidth 调整为比您的自定义标记大一点。

    import seaborn as sns
    sns.set()
    plt.plot(
        range(0,10,2),
        range(0,10,2),
        marker="$abc$",
        markersize=30,
        markeredgewidth=6,
        mec='white',
        color = 'blue'
    )
    plt.plot(
        range(0,10,2),
        range(0,10,2),
        marker="$abc$",
        markersize=30,
        linestyle = 'none',
        color = 'blue'
    )
    

    类似问题Custom plot linestyle in matplotlib

    【讨论】:

    • 您提到的自定义背景问题可以通过将圆圈颜色设置为不是white,而是设置为图形facecolor plt.rcParams['figure.facecolor']来解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多