[英]How to make two separate plots in seaborn from the same dataframe in pandas?
[英]How to make 18 separate scatterplots for 18 different columns from the same pandas Dataframe?
給定以下信息,我如何制作三個小型散點圖:
(df)
: df.columns = ["A", "B", "C", "D", "E", (...)]
selection = ["A", "B", "C", (...)]
value > 5.0
應被塗成blue
,值<= 5.0
等於<= 5.0
應被塗成red
。 我嘗試了以下代碼,但是沒有任何提示?
fig, ax = plt.subplots(4, 5)
for column in selection:
if column in df.columns:
ax.scatter(df[column], if df[column][value > 5.0]: color = 'r', if df[column][value <= 5.0]: color = 'b')
plt.show()
您可以編寫一個快速功能,將值轉換為顏色。 另外,您需要將數組傳遞到每個散點圖中,只傳遞一個。
import numpy as np
@np.vectorize
def colorUp(x):
return 'b' if x <=5.0 else 'r'
# Each scatterplot requires two arrays. You are only passing one;
# I am assuming that this would be the second array passed into
# each '.scatter' call
second_array = np.arange(df.shape[0])
fig, ax = plt.subplots(4, 5)
for i, column in enumerate(selection):
if column in df.columns:
ax[i % 4, i / 4].scatter(df[column], second_array, c = colorUp(df[column]))
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.