简体   繁体   English

散景Y轴反转的vbar图

[英]Bokeh vbar figure with reversed y-axis

I'm trying to create a vbar figure in Bokeh 1.1 for survey ratings data that follow the reverse order that one would normally expect. 我正在尝试在Bokeh 1.1中创建一个vbar数字,用于遵循通常期望的相反顺序的调查评分数据。 In this data set "Excellent" is a 1.0 (the highest score) and "Extremely Poor" is 5.0 (the lowest score) and I am plotting the average values. 在此数据集中,“极好”为1.0(最高分),“极差”为5.0(最低分),我正在绘制平均值。 Hence, I'd like to have a bar that goes from 5.0 at the bottom of the chart up to the top of 1.25, or whatever the average value is. 因此,我希望有一个柱形图,从图表底部的5.0上升到1.25的顶部,或者无论平均值是多少。

In the code below I specified: 在下面的代码中,我指定了:

y_range = (5,1) 

which puts the axis in the right direction but also unfortunately (and as expected) flips the vbar so it comes down from the top. 这使轴指向正确的方向,但不幸的是(又如预期的那样)翻转了vbar,使其从顶部下降。

In another place I used: 在另一个地方,我使用了:

fig.y_range.flipped = True 

as an ad hoc solution for a similar challenge with a line figure, but when applied to a vbar this still produces bars that come down from the top of the chart, whereas I still want the bar to come up from the bottom. 作为针对折线图的类似挑战的临时解决方案,但是当应用于vbar时,它仍然会产生从图表顶部向下的条形,而我仍然希望该条从底部向上条形。

Here's a quick version of the code I've been using: 这是我一直在使用的代码的快速版本:

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)

The ultimate output will have a lot of years and a lot of different averages for each year and I'll have to frequently update it, so I'd rather use a mid-level plotting interface like vbar than create independent rectangles for all the values. 最终输出将有很多年,并且每年会有很多不同的平均值,因此我必须经常更新它,所以我宁愿使用像vbar这样的中级绘图界面,而不是为所有值创建独立的矩形。

Bokeh vbar has bottom=0 as the default so if you flip the axis, and leave that default, then it only makes sense for the bar to flip as well. 散景vbar的默认值是bottom=0 ,因此,如果翻转轴并保留该默认值,则条也必须翻转。 Presumably you would want to set bottom=6 (or whatever makes sense as the "lowest" value on your scale). 大概您想将bottom=6设置bottom=6 (或将刻度上的“最低”值视为有意义的值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM