具有不同 x 起点的散点 matplotlib 图 [英] Scatter matplotlib plot with different x starting points

查看:34
本文介绍了具有不同 x 起点的散点 matplotlib 图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以生成这样的图形:

Is it possible to generate a figure like this:

1) 三行不同
2)线条不是从相同" x点开始
3)稍后将这些散点用线连接

1) Three different lines
2) Lines don't start at the 'same' x points
3) Later connect those scatter points with lines

t = [1, 2, 3, 4, 5, 6, 7]
a = [2, 3, .............]
b = [ , 1, 2, ..........]
c = [ ,  ,  ,  , 2, ....]

谢谢

推荐答案

是.您可以将 numpy.NaN 用于没有相应 t 值的 y 值.代码看起来像这样:

Yes. You can use numpy.NaN for y-values without a corresponding t-value. The code would look something like this:

import matplotlib.pyplot as plt
import numpy as np
t = [1, 2, 3, 4, 5, 6]
a = [2, 3, np.NaN, np.NaN, np.NaN, np.NaN]
b = [np.NaN, 1, 2, np.NaN, np.NaN, np.NaN]
c = [np.NaN, np.NaN, np.NaN, np.NaN, 2, 8]

plt.plot(a,t, marker="o")
plt.plot(b,t, marker="o")
plt.plot(c,t, marker="o")
plt.show()

输出:

这篇关于具有不同 x 起点的散点 matplotlib 图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆