簡體   English   中英

在python中用不同類型的值繪制數據

[英]Plot data with different types of values in python

在此處輸入圖片說明

所有數據點都是藍色的。 我希望 y 軸上 ID-0000 的數據點是不同的顏色。

我想在python中繪制如下數據集:

Timestamp   ID
0.0000      0000
0.000271    0080
0.000495    0000
0.000736    0081
0.000983    0000
0.001239    0165
0.001484    0000
0.001736    018f
0.001984    0000
0.002229    02a0
0.002465    0000
0.002654    02b0
0.002915    0000
0.003143    0316

請幫忙。 謝謝。

這是使用 Numpy 和 Matplotlib 的解決方案:

import numpy as np
import matplotlib.pylab as plt

timestamp = np.linspace(0, 1, 7)
ID = np.array(['0000', '0080', '0000', '018f', '0uu00', 'hello', '0000'])
zero_points = (ID == '0000')  # define a selection mask
non_zero_points = np.logical_not(zero_points)

plt.plot(timestamp[non_zero_points],  ID[non_zero_points], 'bo', label='not 0000')
plt.plot(timestamp[zero_points],  ID[zero_points], 'ro', label='0000')
plt.xlabel('time'); plt.ylabel('values'); plt.legend();

這使:

示例圖

這個想法是創建一個布爾數組,稍后用於選擇每組點。 (可能有更好的方法來寫這個,例如通過為散點圖中的每個點設置一個顏色值......)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM