wrobstory / vincent

A Python to Vega translator
MIT License
2.04k stars 227 forks source link

Can't make bar plot from Pandas timeseries #33

Closed araichev closed 11 years ago

araichev commented 11 years ago

I'm trying to plot a Pandas timeseries as a bar chart via the code below, but it produces a blank html screen. No plot, no axes, no nothing. Am i doing something wrong?

If i change vincent.Bar() to vincent.Line() below, then i get a correct line plot as expected.

import pandas as pd
import vincent
import random

path = 'vega.json'
dates = pd.date_range('1/1/2013 00:00:00', periods=12, freq='m')
data = [random.randint(20, 100) for x in range(len(dates))]
series = pd.Series(data, index=dates)
vis = vincent.Bar()
vis.tabular_data(series, axis_time='month')
vis.update_vis(width=800)
vis.axis_label(x_label='Time', y_label='Data')
vis.to_json(path, html=True)
wrobstory commented 11 years ago

So, after rearranging the Vega spec a bunch of different ways, I can't figure out how to make a time scale play nice with bars in the same way that it does with lines or scatterplots. If it works at all, it will be something in the Marks piece of the spec.

Honestly, if you need a bar plot on a time scale, I would use Bearcart. Just a few lines of code:

import bearcart

html_path = r'index.html'
data_path = r'data.json'
js_path = 'rickshaw.min.js'
css_path = 'rickshaw.min.css'

vis = bearcart.Chart(series, plt_type='bar')
vis.create_chart(html_path=html_path, data_path=data_path,
                 js_path=js_path, css_path=css_path)

Bearcart will do some cool bar chart stuff: http://bl.ocks.org/wrobstory/5560560

dnmiller commented 11 years ago

I tried and came to the same conclusion. Seems like it's really a Vega bug, since one of the goals of a visualization grammar should be to keep scales and marks independent of each other.

I submitted an issue: https://github.com/trifacta/vega/issues/62