作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据以下信息,如何制作三个小散点图:
(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()
最佳答案
您可以编写一个快速函数将值转换为颜色。此外,您需要将数组传递到每个散点图中,仅传递一个。
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()
关于python - 如何为同一个 pandas Dataframe 中的 18 个不同列制作 18 个独立的散点图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111727/
我是一名优秀的程序员,十分优秀!