簡體   English   中英

散景Y軸反轉的vbar圖

[英]Bokeh vbar figure with reversed y-axis

我正在嘗試在Bokeh 1.1中創建一個vbar數字,用於遵循通常期望的相反順序的調查評分數據。 在此數據集中,“極好”為1.0(最高分),“極差”為5.0(最低分),我正在繪制平均值。 因此,我希望有一個柱形圖,從圖表底部的5.0上升到1.25的頂部,或者無論平均值是多少。

在下面的代碼中,我指定了:

y_range = (5,1) 

這使軸指向正確的方向,但不幸的是(又如預期的那樣)翻轉了vbar,使其從頂部下降。

在另一個地方,我使用了:

fig.y_range.flipped = True 

作為針對折線圖的類似挑戰的臨時解決方案,但是當應用於vbar時,它仍然會產生從圖表頂部向下的條形,而我仍然希望該條從底部向上條形。

這是我一直在使用的代碼的快速版本:

import pandas as pd
import numpy as np
from bokeh.plotting import figure
from bokeh.io import show, output_file, output_notebook
from bokeh.transform import dodge

Years = [2010, 2011, 2010, 2012, 2011, 2013, 2013]
ratings_df = pd.DataFrame(Years)
ratings_df.columns = ['Years']
ratings_df['Math_Mean_Ratings'] = [1.0, 2.0, 1.5, 3.0, 5.0, 1.0, 2.0]
ratings_df['German_Mean_Ratings'] = [3.0, 1.0, 2.0, 3.0, 4.0, 1.5, 2.0]
ratings_df

table1 = pd.pivot_table(ratings_df, values=['Math_Mean_Ratings', 'German_Mean_Ratings'], index='Years', aggfunc=np.mean)

fig_title = 'Instructor Ratings: 2010 to 2013'
fig = figure(plot_width=600, plot_height=300, title = fig_title, y_range = (5,1))

fig.vbar(x=dodge('Years', -0.2, range=p2.x_range), width = 0.3, top='Math_Mean_Ratings', source=table1, color='deepskyblue')
fig.vbar(x=dodge('Years', 0.2, range=p2.x_range), width = 0.3, top='German_Mean_Ratings', source=table1, color='midnightblue')

show(fig)

最終輸出將有很多年,並且每年會有很多不同的平均值,因此我必須經常更新它,所以我寧願使用像vbar這樣的中級繪圖界面,而不是為所有值創建獨立的矩形。

散景vbar的默認值是bottom=0 ,因此,如果翻轉軸並保留該默認值,則條也必須翻轉。 大概您想將bottom=6設置bottom=6 (或將刻度上的“最低”值視為有意義的值)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM