As Bryan mentioned, supporting the simple input cases is a priority after the rest of the plots are transitioned over. Currently, this plot is possible with the current api, it just requires using some not well advertised features. There are potential shortcuts that could be added so that an individual chart can infer what you mean by when you provide multiple columns as values.
For the “why”, the issue is that you have to consider from a generalized chart standpoint, this data might make sense for this form of a bar chart, but in the real world, most data is not pre-aggregated. It is normalized, stored in databases. Additionally, it can be aggregated into an infinite number of potential formats that involve some combination of tuples, dicts, nested dicts, arrays of dicts, dicts of arrays, arrays of tuples to communicate through a data structure what we want the chart to do. Instead, we should just tell the chart what to do.
So, if you have this normalized data, you must go through some number of manipulations to get it into this pivoted format. Ok, so that chart turned out to not be what I was expecting, so now I need to aggregate it in some other way. Each step, potentially hitting snags where you have to go look at documentation for how to manipulate the data. However, the key topic here isn’t about manipulating data, it is about expressing how you would like the chart to represent your data. So, initially it will be a bit more painful, but in the end it will be more flexible and much more useful for exploratory analysis and interactive plots.
I’d just suggest taking a look at this example file to see the currently better supported use cases: https://github.com/bokeh/bokeh/blob/master/examples/charts/file/bar_multi.py
On Wednesday, November 4, 2015 at 3:06:05 PM UTC-6, Ignas Brašiškis wrote:
Old api had very simple way of ploting multiple values:
However on new api everything is wrong, I found no way to replicate it.
I tried to replicate it:
from collections import OrderedDict
import pandas as pd
from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.olympics2014 import data
df = pd.io.json.json_normalize(data[‘data’])
filter by countries with at least one medal and sort
df = df[df[‘medals.total’] > 0]
df = df.sort(“medals.total”, ascending=False)
get the countries and we group the data by medal type
countries = df.abbr.values.tolist()
gold = df[‘medals.gold’].astype(float).values
silver = df[‘medals.silver’].astype(float).values
bronze = df[‘medals.bronze’].astype(float).values
build a dict containing the grouped data
medals = OrderedDict(countries=countries, bronze=bronze, silver=silver, gold=gold)
any of the following commented are also alid Bar inputs
medals = pd.DataFrame(medals)
#medals = list(medals.values())
bar = Bar(medals, values=‘gold’, label=“countries”, title=“Stacked bars”)
However values keyword argument does not accept multiple columns. That’s stupid.
You can replicate something by duplicating table, puting everything in single column and adding new column with type of medal. And using that column as ‘group’.
But why? Isn’t whole point of bar plot to comprehend data set from multiple columns to groups, without resorting to data move?
Am I missing something?