![](/img/trans.png)
[英]Setting Colors For Positive and Negative Values in Scatter Plot with Matplotlib with 2 Custom Colors
[英]Scatter Plot with different color for positive and negative values
這是我的問題
這是我的兩個 DataFrame 的示例(實際上我有 30 列)
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.DataFrame({"Marc":[6,0,8,-30,-15,0,-3],
"Elisa":[0,1,0,-1,0,-2,-4],
"John":[10,12,24,-20,7,-10,-30]})
df1 = pd.DataFrame({"Marc":[8,2,15,-12,-8,0,-35],
"Elisa":[4,5,7,0,0,1,-2],
"John":[20,32,44,-30,15,-10,-50]})
我想用兩個不同的 colors 創建一個散點圖 plot:如果 df1 的分數為負數,則為 1 種顏色,如果為正數,則為一種顏色,但我真的不知道該怎么做。
我已經通過使用 matplotlib 做到了這一點
plt.scatter(df,df1);
而且我還檢查了此鏈接鏈接,但問題是我有兩個 Pandas Dataframe 而不是 numpy 數組,如此鏈接。 因此我不能使用c= np.sign(df.y)
方法。 我想保留 Pandas DataFrame 因為我有很多專欄,但我真的堅持下去。
如果有人有解決方案,歡迎您!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.