简体   繁体   English

为每个唯一ID创建一个图

[英]Create a plot for each unique ID

Given the dataframe df, I could use some help to create two different scatter plots one for the x,y cordinates, the c value is used for the color map with the id "aa" and one with the x,y cordinates, the c value is used for the color map with the id "bb". 给定数据帧df,我可以使用一些帮助来创建两个不同的散点图,一个用于x,y坐标,c值用于ID为“ aa”的颜色映射,另一个用于x,y坐标,c值用于ID为“ bb”的颜色图。 With the actual data there are over 1000 unique id's. 实际数据中有超过1000个唯一ID。

import numpy as np
import matplotlib.pyplot as plt
import pyodbc
import pandas as pd


#need to add the 
data = {'x':[2,4,6, 8,10, 12], 'y':[2,4,6, 8,10, 12], 'c': [.2,.5,.5,.7,.8,.9], 'id':['aa','aa','aa','bb','bb','bb']}

df = pd.DataFrame(data)

print (df)

for d in df.groupby(df['id']):

    plt.scatter(d[1][['x']],d[1][['y']], c=d[1][['c']], s=10, alpha=0.3, cmap='viridis')
    clb = plt.colorbar();
    plt.show()

Returns this error: ValueError: RGBA values should be within 0-1 range 返回此错误:ValueError:RGBA值应在0-1范围内

Try this: 尝试这个:

df = pd.DataFrame(data)

for d in df.groupby(df['id']):
    plt.plot(d[1][['x','y']])
    plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM