-1
A
回答
0
c_map = {'US': 'b', 'UK': 'r', ...}
fig, ax = plt.subplots(1, 1)
ax.scatter(x, y, c=[c_map[_] for _ in country])
0
我試過這段代碼,它似乎解決了這個問題。
fig, ax = plt.subplots()
for dd,daata in P.groupby('Country'):
ax.plot(daata['X'],daata['Y'],'o')
-1
在Altair解決這個問題。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
cat = ["US"] *5 + ["UK"]*4
x = np.append(np.arange(1,6), np.arange(2.5,4.1,0.5))
y = np.random.randint(12,24, size=len(cat))
df = pd.DataFrame({"cat":cat, "x":x, "y":y})
from altair import *
Chart(df).mark_point().encode(x='x', y='y', color='cat').configure_cell(width=200, height=150)
相關問題
- 1. 在Matplotlib
- 2. 在Matplotlib
- 3. 在matplotlib
- 4. 在MatPlotLib
- 5. 在matplotlib
- 6. 在Matplotlib
- 7. 在matplotlib
- 8. 在matplotlib
- 9. 在matplotlib
- 10. 在Matplotlib
- 11. 在matplotlib
- 12. 在Matplotlib
- 13. 在matplotlib
- 14. 在Matplotlib
- 15. MonthLocator在Matplotlib
- 16. 如何在matplotlib
- 17. 在python matplotlib
- 18. 在Matplotlib底圖
- 19. 如何在matplotlib
- 20. 歇//在matplotlib
- 21. 如何在matplotlib
- 22. 差異在matplotlib
- 23. 的Python:在Matplotlib
- 24. 創建在matplotlib
- 25. 蟒蛇:在matplotlib
- 26. plt.figure()與在Matplotlib
- 27. 標籤在matplotlib
- 28. 「SuperAxis」在matplotlib插曲
- 29. 現在畫和Matplotlib
- 30. 錯誤而在Matplotlib
基本上我的數據集是在一個數據幀大熊貓爲c_map變量的形式,我使用c_map = P [「國家」]。to_dict然後使用的建議的其餘部分。但有一個錯誤'instancemethod'對象沒有屬性'__getitem__' – user40465
我試過plt.plot(df ['x'],df ['y'],c = df ['country']),沒有錯誤但圖表不會彈出 – user40465