如何将两个图例堆叠在一起?

问题描述 投票:0回答:0

我用

matplotlib
画了下图:

使用的代码如下:

import matplotlib.pyplot as plt
import numpy as np

# Generate data
x = np.linspace(0, 10, 10, dtype=float)
x_mid = x[:-1] + np.diff(x) / 2.0
y = np.random.rand(len(x) - 1) * 100
yerr = np.random.rand(len(x) - 1) * 20
# Plot
fig = plt.figure()
ax = fig.add_subplot()
ax.errorbar(x_mid, y=y, yerr=yerr, color='blue', fmt='o', markersize=10, label='Data')
ax.stairs(y, x, baseline=None, color='blue', linewidth=2, linestyle='solid', label='Data')

ax.legend()

plt.show()

生成Legend遇到困难。虽然我可以用

Line2D([0], [0], marker='|', ls='-', c='blue', markersize=16, markeredgewidth=16)
来生成一个十字线,但是它中间没有一个点。

我无法生成中间有一个点的十字准线。我怎样才能实现我的目标?在Line2D生成的十字准线中间叠加一个点是可行的,但是如何操作呢?

python matplotlib
© www.soinside.com 2019 - 2024. All rights reserved.