0
我有一個包含4列的數據集。 2列是點的標籤(['Drug','Layer']),2是點coordiantes(x ='節點',y ='CoreIndex')。 毒品的基數是2,層數是15.所以我有30點的陰謀。我想要不同顏色的圖層。熊貓groupby散點圖不變色
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
fig,ax= plt.subplots(figsize=[10,5])
rgb_values = sns.color_palette("Set2", 19)
for name,group in data_pos.groupby(['Drug','Layer']):
if 'lsd' in name:
group.plot(x='Nodes', y='CoreIndex', kind='scatter', ax=ax, label=name, c=rgb_values[name[1]+3], marker='s', s=100)
else:
group.plot(x='Nodes', y='CoreIndex', kind='scatter', ax=ax, label=name, c=rgb_values[name[1]+3], s=100)
plt.legend()
plt.show()
有什麼不好?
數據:
data_pos = pd.DataFrame([['lsd', 1L, 21L, 100L],
['lsd', 10L, 14L, 76L],
['lsd', 11L, 18L, 126L],
['lsd', 12L, 28L, 70L],
['lsd', 13L, 12L, 82L],
['lsd', 14L, 23L, 87L],
['lsd', 15L, 19L, 71L],
['lsd', 2L, 20L, 76L],
['lsd', 3L, 16L, 59L],
['lsd', 4L, 16L, 118L],
['lsd', 5L, 14L, 109L],
['lsd', 6L, 10L, 134L],
['lsd', 7L, 16L, 96L],
['lsd', 8L, 11L, 148L],
['lsd', 9L, 18L, 130L],
['lsd', 1L, 22L, 91L],
['lsd', 10L, 14L, 99L],
['lsd', 11L, 29L, 93L],
['lsd', 12L, 37L, 125L],
['lsd', 13L, 13L, 139L],
['lsd', 14L, 19L, 143L],
['lsd', 15L, 18L, 78L],
['lsd', 2L, 27L, 68L],
['lsd', 3L, 14L, 101L],
['lsd', 4L, 15L, 90L],
['lsd', 5L, 16L, 112L],
['lsd', 6L, 11L, 50L],
['lsd', 7L, 15L, 115L],
['lsd', 8L, 13L, 139L],
['lsd', 9L, 17L, 67L],
['lsd', 1L, 15L, 82L],
['lsd', 10L, 13L, 133L],
['lsd', 11L, 19L, 98L],
['lsd', 12L, 27L, 104L],
['lsd', 13L, 11L, 90L],
['lsd', 14L, 25L, 73L],
['lsd', 15L, 17L, 126L],
['lsd', 2L, 22L, 62L],
['lsd', 3L, 14L, 149L],
['lsd', 4L, 16L, 108L],
['lsd', 5L, 13L, 91L],
['lsd', 6L, 10L, 132L],
['lsd', 7L, 15L, 136L],
['lsd', 8L, 15L, 65L],
['lsd', 9L, 14L, 142L],
['pcb', 1L, 17L, 104L],
['pcb', 10L, 13L, 68L],
['pcb', 11L, 23L, 71L],
['pcb', 12L, 20L, 79L],
['pcb', 13L, 11L, 96L],
['pcb', 14L, 15L, 74L],
['pcb', 15L, 16L, 63L],
['pcb', 2L, 13L, 34L],
['pcb', 3L, 18L, 67L],
['pcb', 4L, 18L, 70L],
['pcb', 5L, 15L, 143L],
['pcb', 6L, 14L, 48L],
['pcb', 7L, 16L, 125L],
['pcb', 8L, 15L, 94L],
['pcb', 9L, 19L, 69L],
['pcb', 1L, 15L, 72L],
['pcb', 10L, 12L, 59L],
['pcb', 11L, 21L, 66L],
['pcb', 12L, 17L, 71L],
['pcb', 13L, 14L, 42L],
['pcb', 14L, 17L, 93L],
['pcb', 15L, 13L, 148L],
['pcb', 2L, 12L, 72L],
['pcb', 3L, 15L, 137L],
['pcb', 4L, 13L, 146L],
['pcb', 5L, 13L, 137L],
['pcb', 6L, 12L, 111L],
['pcb', 7L, 14L, 131L],
['pcb', 8L, 12L, 113L],
['pcb', 9L, 16L, 134L],
['pcb', 1L, 14L, 64L],
['pcb', 10L, 12L, 83L],
['pcb', 11L, 23L, 79L],
['pcb', 12L, 15L, 137L],
['pcb', 13L, 14L, 69L],
['pcb', 14L, 28L, 89L],
['pcb', 15L, 20L, 83L],
['pcb', 2L, 13L, 56L],
['pcb', 3L, 23L, 58L],
['pcb', 4L, 16L, 77L],
['pcb', 5L, 14L, 111L],
['pcb', 6L, 14L, 51L],
['pcb', 7L, 14L, 122L],
['pcb', 8L, 12L, 58L],
['pcb', 9L, 17L, 54L]],columns=['Drug','Layer','Nodes','CoreIndex'])
您能否提供[工作示例](https://stackoverflow.com/help/mcve)? – Tbaki
是的,我上傳了一個新版本 –