小编Vin*_*var的帖子

创建带有实心正方形和加号的自定义标记

我想创建具有自定义标记样式的线图。我特别想要一个带有加号或乘积符号的正方形(填充/未填充)。这个怎么做。下面的代码不起作用

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np

# Sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)

# Create a figure and axis
fig, ax = plt.subplots()

# Define the custom marker as a combination of a filled square and a plus symbol
def custom_marker():
    square = mpatches.Rectangle((-0.5, -0.5), 1, 1, linewidth=0, edgecolor='none', facecolor='red', zorder=2)
    plus = plt.Line2D([0, 0], [-0.4, 0.4], color='white', linewidth=2, zorder=3)
    plus2 = plt.Line2D([-0.4, 0.4], [0, 0], color='white', linewidth=2, zorder=3) …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

0
推荐指数
1
解决办法
180
查看次数

标签 统计

matplotlib ×1

python ×1