python - 空心圆符号中的误差线

标签 python matplotlib

当我使用 plt.errorbars 时,我希望灰色点完全不出现在空心圆符号内。我发现了一个类似的问题,但它使用了 ggplot。

Error bars show through open symbol

除非别无选择,否则我会坚持使用 pyplot。我的代码如下。提前致谢。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,5,0.1)
y = np.sin(x)
yerr = np.random.randint(2,size=len(x))
plt.errorbar(x,y,yerr=yerr, color='gray', fmt='.', zorder=1)
plt.plot(x,y,'ro', mfc='none', label='My work')
plt.legend(numpoints=1)
plt.show() 

enter image description here

最佳答案

使用fmt='o':

plt.errorbar(x,y,yerr=yerr, color='gray', fmt='o', mfc='white', zorder=1)

包含 mfc='white' 以将标记的背景颜色设置为白色。

参见 plot对于其他 fmt 字符。

关于python - 空心圆符号中的误差线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18212313/

相关文章:

python - 如何处理具有大量记录的django admin中的选择框

python - 如何为 matplotlib 图分配变量名?

python - dask 如何从调度器向 worker 分发数据?

python - 在 Tensorflow 1.9 的一个脚本中运行不同的模型

python - 我可以将 Papermill 和 Scrapbook 与 AWS EMR Notebooks 结合使用吗?

python - 如何使用不同大小的 host_subplots 保存我的图表?

Python - 创建模式列表

python - 如何用matplotlib绘制条形图时间轴?

python - X 轴上的百分位数与 matplotlib

python - 根据运行时变量的值播放不同的视频文件