You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自动用线条连接Scipy probplot概率图中的标记点

给Scipy probplot生成的概率图标记点添加连线

由于stats.probplot的plot参数没有直接提供连接标记点的设置选项,你可以利用它返回的结果手动绘制连线,具体操作如下:

  • 调用probplot时,它会返回一个元组,其中第一个元素包含了绘制概率图所需的理论分位点和排序后的样本值
  • 使用matplotlib的plot函数,基于这些数据直接绘制连接标记点的线条
  • 通过zorder参数调整层级,确保散点在连线上方,维持清晰的视觉效果

修改后的完整代码:

import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

nsample = 20
np.random.seed(100)

fig = plt.figure()
ax = fig.add_subplot(111)
x = stats.t.rvs(3, size=nsample)
res = stats.probplot(x, plot=plt)

# 提取概率图的坐标数据
theoretical_quantiles, sample_data = res[0]
# 绘制标记点的连线
ax.plot(theoretical_quantiles, sample_data, 'b-', zorder=0)

# 调整散点样式
scatter_line = ax.get_lines()[0]
scatter_line.set_markeredgecolor('b')
scatter_line.set_markerfacecolor('b')

plt.show()

内容的提问来源于stack exchange,提问作者ClimberS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 04:33:29