使标记边在Matplotlib中相互穿过

2024-04-25 07:36:44 发布

您现在位置:Python中文网/ 问答频道 /正文

使用matplotlib和常规打印功能,我可以使标记的边彼此穿过,而不是像图中所示那样堆叠吗

enter image description here


Tags: 标记功能matplotlib常规
1条回答
网友
1楼 · 发布于 2024-04-25 07:36:44

没有内置选项将标记的面颜色与边缘分开。因此,为了使标记边清晰可见,可以绘制两个图,一个用于面,另一个用于边

import numpy as np; np.random.seed(32)
import matplotlib.pyplot as plt

x = np.arange(30)
y = np.cumsum(np.random.randn(30))

fig, (ax, ax2) = plt.subplots(1,2, figsize=(5.5,2))

## plot
ax.plot(x,y, marker="s", ms=15, color="C3")
ax.plot(x,y, marker="s", ms=15, color="none", mec="black")

## scatter
ax2.scatter(x,y, marker="s", s=15**2, facecolor="C3")
ax2.scatter(x,y, marker="s", s=15**2, facecolor="none", edgecolor="black")


ax.set_title("plot")
ax2.set_title("scatter")
fig.tight_layout()
plt.show()

enter image description here

相关问题 更多 >