1
我有以下數據框df
:如何使用漸變顏色爲配色圖上的顏色條?
time_diff avg_trips_per_day
0.450000 1.0
0.483333 1.0
0.500000 1.0
0.516667 2.0
0.533333 5.0
然後我創建了一個分佈圖如下ax = sns.distplot(df['time_diff'],hist="true"
。
我想使用漸變對條進行着色:應將較暗的顏色分配給較高概率的值。
我試圖做這種方式,但它沒有工作:
norm = plt.Normalize(df["time_diff"].values.min(), df["time_diff"].values.max())
colors = plt.cm.YlGnBu(norm(df_imh_unique["time_diff"]))
ax = sns.distplot(df['time_diff'],hist="true", color=colors)
感謝。如果我在開始時使用'plt.figure(figsize =(14,8))',我無法調整此圖。它總是很小。 – Dinosaurius
另外我需要保持我的大小爲'25'的箱子。在我的代碼中,我使用'plt.xticks(np.arange(min(df_day_route_veh_counts ['time_diff']),max(df_day_route_veh_counts ['time_diff'])+ 100,25.0))''。我如何將這種方法適用於您的代碼? – Dinosaurius
'plt.subplots(figsize =(14,8))'設置數字大小。 'plt.xticks'不設置bin大小。它在軸上設置刻度的位置。但它也可以在這個代碼中工作。如果要更改直方圖的bin大小,則需要使用'np.histogram'的'bins'參數。 – ImportanceOfBeingErnest