(matplotlib,python 2.7)
尝试为x和y制作散点图:
class Ideone
{
public static void main (String[] args) {
System.out.println(days()[dow(8,10,2015)]);
}
public static String[] days() {
return new String[] {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
}
public static int dow(int d, int m, int y) {
if (m < 3) {
m += 12;
y--;
}
return (d + (int)((m+1)*2.6) + y + (int)(y/4) + 6*(int)(y/100) + (int)(y/400) + 6) % 7;
}
}
散点图的代码当然是:
x = [0, 1, 2, 3, 4]
y = [1, 2, 3, 4, 5]
但是,考虑到下面的z列表,我希望y的颜色在z = 0时为黑色,在z = 1时为橙色。
plt.scatter(x, y)
我该怎么办?试过谷歌和其他stackoverflow帖子,但到目前为止没有成功..
谢谢!
答案 0 :(得分:0)
您似乎只需要使用c
keyword argument指定颜色:
.chart-bar {
-fx-bar-fill: #22bad9;
-fx-background-color: linear-gradient(derive(-fx-bar-fill,-30%), derive(-fx-bar-fill,-40%)),
linear-gradient(derive(-fx-bar-fill,80%), derive(-fx-bar-fill, 0%)),
linear-gradient(derive(-fx-bar-fill,30%), derive(-fx-bar-fill,-10%));
-fx-background-insets: 0,1,2;
-fx-background-radius: 5 5 0 0, 4 4 0 0, 3 3 0 0;
}
当然,你可以通过将颜色值转换为matplotlib的颜色代码的映射来获得更好的效果:
plt.scatter(x, y, c=['k' if zz == 0 else 'orange' for zz in z])
这里的优点很明显 - 为情节添加更多颜色要容易得多。