如何根据以下信息制作三个小散点图:
(df)
,共有50列: df.columns = ["A", "B", "C", "D", "E", (...)]
selection = ["A", "B", "C", (...)]
value > 5.0
的标记应为blue
,标记为<= 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()
答案 0 :(得分:2)
您可以编写快速功能将值转换为颜色。此外,您需要将数组传递到每个只传递一个的散点图中。
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()