[英]Plot data with different types of values in python
這是使用 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.