Giter Site home page Giter Site logo

vincent's Introduction

Status

2016-06-18 Update

If you are interested in this library, I would direct you to the Altair project: https://github.com/altair-viz/altair It supports the latest version of vega, is fully-featured, has a great development team, and has been developed with the support of the Vega team at UW.

There will be no more updates, closed issues, or PR merges for the Vincent project. Thanks so much to everyone who tried it or used it along the way.

#Vincent

Travs-CI status

Vincent

###A Python to Vega translator

The folks at Trifacta are making it easy to build visualizations on top of D3 with Vega. Vincent makes it easy to build Vega with Python.

Concept

The data capabilities of Python. The visualization capabilities of JavaScript.

Vincent takes Python data structures and translates them into Vega visualization grammar. It allows for quick iteration of visualization designs via getters and setters on grammar elements, and outputs the final visualization to JSON.

Perhaps most importantly, Vincent groks Pandas DataFrames and Series in an intuitive way.

Installation

$pip install vincent

Warning: requires Pandas, which isn't a simple pip install if you don't already have Numpy installed. If you want to go all-pip, I recommend $pip install numpy then $pip install pandas. Or just use Anaconda.

Docs

Here.

Quickstart

Let's start with some varying data, and then show some different ways to visualize them with Vincent.

Starting with a simple bar chart:

import vincent
bar = vincent.Bar(multi_iter1['y1'])
bar.axis_titles(x='Index', y='Value')
bar.to_json('vega.json')

bars

Plotting a number of lines:

line = vincent.Line(multi_iter1, iter_idx='index')
line.axis_titles(x='Index', y='Value')
line.legend(title='Categories')

lines

Or a real use case, plotting stock data:

line = vincent.Line(price[['GOOG', 'AAPL']])
line.axis_titles(x='Date', y='Price')
line.legend(title='GOOG vs AAPL')

stocks1

Color brewer scales are built-in. For example, plotting a scatter plot with the Set3 colors:

scatter = vincent.Scatter(multi_iter2, iter_idx='index')
scatter.axis_titles(x='Index', y='Data Value')
scatter.legend(title='Categories')
scatter.colors(brew='Set3')

scatter

Area charts:

area = vincent.Area(list_data)

area

Stacked Area Charts from a DataFrame:

stacked = vincent.StackedArea(df_1)
stacked.axis_titles(x='Index', y='Value')
stacked.legend(title='Categories')
stacked.colors(brew='Spectral')

areastack

stacked = vincent.StackedArea(price)
stacked.axis_titles(x='Date', y='Price')
stacked.legend(title='Tech Stocks')

areastack2

Stacked Bar Charts from a DataFrame:

stack = vincent.StackedBar(df_2)
stack.legend(title='Categories')
stack.scales['x'].padding = 0.1

barstack1

stack = vincent.StackedBar(df_farm.T)
stack.axis_titles(x='Total Produce', y='Farms')
stack.legend(title='Produce Types')
stack.colors(brew='Pastel1')

barstack2

Grouped Bars from a DataFrame:

group = vincent.GroupedBar(df_2)
group.legend(title='Categories')
group.colors(brew='Spectral')
group.width=750

groupbar1

group = vincent.GroupedBar(df_farm)
group.axis_titles(x='Total Produce', y='Farms')
group.legend(title='Produce Types')
group.colors(brew='Set2')

groupbar2

Pie charts:

vis = vincent.Pie(farm_1)
vis.legend('Farm 1 Fruit')

pie

Donut charts:

vis = vincent.Pie(farm_1, inner_radius=200)
vis.colors(brew="Set2")
vis.legend('Farm 1 Fruit')

donut

Simple maps can be built quickly (all data can be found in the vincent_map_data repo):

world_topo = r'world-countries.topo.json'
geo_data = [{'name': 'countries',
             'url': world_topo,
             'feature': 'world-countries'}]

vis = vincent.Map(geo_data=geo_data, scale=200)

simplemap

Also with multiple map layers:

geo_data = [{'name': 'counties',
             'url': county_topo,
             'feature': 'us_counties.geo'},
            {'name': 'states',
             'url': state_topo,
             'feature': 'us_states.geo'}]

vis = vincent.Map(geo_data=geo_data, scale=1000, projection='albersUsa')
del vis.marks[1].properties.update
vis.marks[0].properties.update.fill.value = '#084081'
vis.marks[1].properties.enter.stroke.value = '#fff'
vis.marks[0].properties.enter.stroke.value = '#7bccc4'

multiplelayer

Maps can be bound with data to Pandas DataFrames for choropleth visualizations (see here for map data munging):

geo_data = [{'name': 'counties',
             'url': county_topo,
             'feature': 'us_counties.geo'}]

vis = vincent.Map(data=merged, geo_data=geo_data, scale=1100, projection='albersUsa',
          data_bind='Unemployment_rate_2011', data_key='FIPS',
          map_key={'counties': 'properties.FIPS'})
vis.marks[0].properties.enter.stroke_opacity = ValueRef(value=0.5)
vis.to_json('vega.json')

binding1

It can be rebound on the fly with new data and color brewer scales:

vis.rebind(column='Median_Household_Income_2011', brew='YlGnBu')

binding2

For more examples, including how to build these from scratch, see the examples directory, or the docs.

Built from Scratch

To see how the charts are being built with Vincent -> Vega grammar, see the charts.py module.

Building the bar chart from scratch will provide a quick example of building with Vincent:

import pandas as pd
from vincent import (Visualization, Scale, DataRef, Data, PropertySet,
                     Axis, ValueRef, MarkRef, MarkProperties, Mark)

df = pd.DataFrame({'Data 1': [15, 29, 63, 28, 45, 73, 15, 62],
                   'Data 2': [42, 27, 52, 18, 61, 19, 62, 33]})

#Top level Visualization
vis = Visualization(width=500, height=300)
vis.padding = {'top': 10, 'left': 50, 'bottom': 50, 'right': 100}

#Data. We're going to key Data 2 on Data 1
vis.data.append(Data.from_pandas(df, columns=['Data 2'], key_on='Data 1', name='table'))

#Scales
vis.scales.append(Scale(name='x', type='ordinal', range='width',
                        domain=DataRef(data='table', field="data.idx")))
vis.scales.append(Scale(name='y', range='height', nice=True,
                        domain=DataRef(data='table', field="data.val")))

#Axes
vis.axes.extend([Axis(type='x', scale='x'), Axis(type='y', scale='y')])

#Marks
enter_props = PropertySet(x=ValueRef(scale='x', field="data.idx"),
                                     y=ValueRef(scale='y', field="data.val"),
                                     width=ValueRef(scale='x', band=True, offset=-1),
                                     y2=ValueRef(scale='y', value=0))
update_props = PropertySet(fill=ValueRef(value='steelblue'))
mark = Mark(type='rect', from_=MarkRef(data='table'),
            properties=MarkProperties(enter=enter_props,
            update=update_props))

vis.marks.append(mark)
vis.axis_titles(x='Data 1', y='Data 2')
vis.to_json('vega.json')

barscratch

Because the Vega elements are represented by Python classes, it can be difficult to get a good idea of what the Vega grammar looks like:

In [5]: vis.marks[0]
<vincent.marks.Mark at 0x110d630d0>

However, at almost any point in the Vincent stack, you can call the grammar() method to output the Vega grammar as Python data structures:

>>>vis.marks[0].grammar()
{u'from': {u'data': u'table'},
 u'properties': {u'enter': {u'width': {u'band': True,
    u'offset': -1,
    u'scale': u'x'},
   u'x': {u'field': u'data.idx', u'scale': u'x'},
   u'y': {u'field': u'data.val', u'scale': u'y'},
   u'y2': {u'scale': u'y', u'value': 0}},
  u'update': {u'fill': {u'value': u'steelblue'}}},
 u'type': u'rect'}
>>>vis.marks[0].properties.enter.x.grammar()
{u'field': u'data.idx', u'scale': u'x'}

or you can simply output it to a string of JSON:

>>>print(vis.marks[0].to_json())
{
  "type": "rect",
  "from": {
    "data": "table"
  },
  "properties": {
    "update": {
      "fill": {
        "value": "steelblue"
      }
    },
    "enter": {
      "y": {
        "field": "data.val",
        "scale": "y"
      },
      "width": {
        "band": true,
        "scale": "x",
        "offset": -1
      },
      "y2": {
        "scale": "y",
        "value": 0
      },
      "x": {
        "field": "data.idx",
        "scale": "x"
      }
    }
  }
}

Vincent is built around classes and attributes that map 1:1 to Vega grammar, for easy getting, setting, and deleting of grammar elements:

>>>vis.marks[0].properties.enter.grammar()
{u'width': {u'band': True, u'offset': -1, u'scale': u'x'},
 u'x': {u'field': u'data.idx', u'scale': u'x'},
 u'y': {u'field': u'data.val', u'scale': u'y'},
 u'y2': {u'scale': u'y', u'value': 0}}
 >>> del vis.marks[0].properties.enter.width
 >>> vis.marks[0].properties.enter.y2.scale = 'y2'
 >>> vis.marks[0].properties.enter.grammar()
{u'x': {u'field': u'data.idx', u'scale': u'x'},
 u'y': {u'field': u'data.val', u'scale': u'y'},
 u'y2': {u'scale': u'y2', u'value': 0}}

Contributors

Huge thanks to all who have contributed to Vincent development:

  • Rob Story (wrobstory)
  • Dan Miller (dnmiller)
  • Peter Lubell-Doughtie (pld)
  • Lx Yu (lxyu)
  • Damien Garaud (garaud)
  • Abraham Flaxman (aflaxman)
  • Mahdi Yusuf (myusuf3)
  • Richard Maisano (maisano)
  • Julian Berman (Julian)
  • Chris Rebert (cvrebert)
  • Wojciech Bederski (wuub)
  • Min RK (minrk)
  • Drazen Lucanin (kermit666)
  • tlukasiak

Dependencies

  • pandas
  • pkgtools

Testing:

  • mock
  • nose

PSA: you can use pieces of Vincent without Pandas, but its tricky. Besides, Pandas is awesome- try it!

vincent's People

Contributors

aflaxman avatar ajrenold avatar cvrebert avatar dennisobrien avatar dnmiller avatar ellisonbg avatar garaud avatar heinrichfilter avatar hellerpdx avatar jaredly avatar julian avatar kennethdamica avatar lxyu avatar maisano avatar metakermit avatar minrk avatar myusuf3 avatar pawelmhm avatar tlukasiak avatar wrobstory avatar wuub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vincent's Issues

IPython notebook support breaks with static views

Because the vincent IPython notebook integration relies on require.js, it doesn't work with nbviewer and static HTML views like blogs.

I haven't looked closely at the javascript, but we got around this in mpld3 by using a conditional statement that detects whether require.js is available (see https://github.com/jakevdp/mpld3/blob/master/mpld3/_objects.py#L186). It would be nice to do something similar for vincent.

Another small thing on the IPython notebook integration: the default setting of a 100%-width div produces poor results at times. I've ended up defining my own display function, which looks like this:

from IPython.display import HTML
from vincent.visualization import _vega_t
import random

def display_natural(obj):
    """
    Display a vincent object in IPython notebook
    without forcing it to 100% of the page width
    """
    # the following is adapted from Visualization._repr_html_
    id = random.randint(0, 2 ** 16)
    html = '<div id="vis%d"></div>' % id
    html += '<script>\n'
    html += _vega_t % (obj.to_json(pretty_print=False), id) + '\n'
    html += '</script>\n'
    return HTML(html)

I would appreciate if vincent did this by default (or at least let the user configure it), but there may be a piece that I'm overlooking!

LegendProperties example for Maps

I'm having some trouble sorting out the LegendProperties syntax for vincent.Map. Specifically, I want to set the legend labels, which seems like it should take a list but appears to require a ValueRef, and it's not clear from other examples how to pass in an array property.

Would a short example be possible?

Otherwise, vincent is fantastic. Thanks!

Plans to Depend on ipynb

Hi there.

I forked and was about to fix a bug with unknown types passed to tabular_data but I'm glad to see it's been rewritten (and the bug fixed) as part of your new release, and even gladder to see that the new interface won't take the jumble of types that tabular_data does.

I see that in __init__.py you now import ipynb for some reason: presumably this only will be an optional dep (and its import should be guarded and ignored if non-present?)

Thanks for a great lib!

Proposal to add ORM-style classes

Vincent currently exposes all of the Vega JSON. This has pros and cons. The user doesn't have to rely on Vincent fully implementing Vega to generate images, but the user is also free to generate nonsense Vega that won't render.

After spending a fair amount of time debugging generated JSON, I'm proposing to add some ORM-style classes. It would work something like this:

x = Scale(name='x')
x.reverse = True  # good
x.reverse = 5 # raises an exception
help(Scale.reverse) # shows __doc__ for the reverse property

Some advantages to this approach:

  • Users would have access to valid Vega gramar without having to scour the Vega docs.
  • Generated JSON would be guaranteed to render.
  • The API would be more accessible. There's no need to remember positions of items in tuples and doc strings would help impatient new users.
  • __str__ and __repr__ methods could be added to make the API more friendly.

And some disadvantages:

  • Tightly couples Vincent and Vega - could be maintenance headache.
  • Vega features might be unintentionally left out and new Vega features might not be immediately available in Vincent.
  • It's more work.

I think most of the disadvantages can be overcome with the right implementation. Below is a working example that implements the above:

import json


def field_property(validator):
    """Decorator to define properties that map to the internal `_field`
    dict.

    The argument is a "validator" function that should return no value but
    raise an exception if the provided value is not valid Vega. If the
    validator throws no exception, then the value is assigned to the
    `_field` dict using the validator function name as the key.

    The validator function should take only one argument, so that no `self`
    argument is included - the validator should not modify the class.

    The docstring for the property is taken from the validator's docstring.
    """
    name = validator.__name__

    def setter(self, value):
        validator(value)
        self._field[name] = value

    def getter(self):
        return self._field.get(name, None)

    def deleter(self):
        if name in self._field:
            del self._field[name]

    return property(getter, setter, deleter, validator.__doc__)


class Scale(object):
    def __init__(self, name):
        self._field = {}
        self.name = name

    @field_property
    def name(value):
        """Name of the scale."""
        if not isinstance(value, str):
            raise TypeError('name must be string')

    @field_property
    def reverse(value):
        """If `True`, flip the range of the scale."""
        if not isinstance(value, bool):
            raise TypeError('reverse must be bool')

    def to_json(self):
        return json.dumps(self._field)

This has the advantage that unused fields don't get serialized and bloat the generated JSON:

print(Scale.reverse.__doc__)
>>> 'If `True`, flip the range of the scale.'
x = Scale(name='x')
x.reverse is None
>>> True
x.to_json()
>>> '{"name": "x"}'
x.reverse = True
>>> '{"name": "x", "reverse": true}'
x.reverse = False
x.to_json()
>>> '{"name": "x", "reverse": false}'
del x.reverse
x.to_json()
>>> '{"name": "x"}'
x.reverse = 5
>>> [...etc...] TypeError: reverse must be bool

Though the serialization would likely be done by some containing class.

Power users would still have access to the original API, and the _field attribute is always available if there's some unimplemented Vega feature people need access to.

I'd like to open this up for discussion. This would be a significant departure from the current API and wouldn't be finished for some time. Any thoughts, suggestions, critiques, etc. are welcome below.

graphs not saved in ipython notebook

The vincent examples notebook when run through the ipython notebook, saved and reopened. Doesn't show the graphs again. the cells have to be run everytime to get the graphs.

Ipython notebook 1.1.0

Ability to add multiple tabular datasets

Right now you can only add one set of data via the tabular_data method- it lives in vis.data[0], and every time you add a new set, it just overwrites the old one.

There is an option to append the tabular data, but it would be best if one could add multiple sets of tabular data, and then reference each of them.

If anyone takes this on, make sure you check for references to the "table" name in places like the Maps subclass- right now map data always binds to data[0]['table']. Making this more flexible will require some added functionality to bind different datasets to different map components.

docs. why not using MPL?

although your graphs look really nice, please add a statement on the docs:
what does vega/vincent offer ofer MPL?

Javascript error adding output

So i downloaded and installed the latest bits from GitHub. Now out of box the graphs are getting generated on IPython (Firefox & Safari). The first time I run code everything is nice and dandy.

But if I re-execute the code in the block I get the following error shown on the screen along with the graph. So the graphs are still generating but there is this error also displayed above the graph.

Javascript error adding output!
Error: Mismatched anonymous define() module: [object Object] http://requirejs.org/docs/errors.html#mismatch
See your browser Javascript console for more details.

upon further inspection I also see this line in my Web Console (Firefox) don't know if it's related to this error or not.

TypeError: canvas is null                      vega.js:2022

This is the code that I am using as a test:

import pandas as pd
import vincent

vincent.core.initialize_notebook()

list_data = [10, 20, 30, 20, 15, 30, 15]
bar = vincent.Bar(list_data)

bar.display()

Thanks

Anand

Status

So what's the current development status? Is this project abandoned? Is there an active fork out there?

I'd love to use vincent for a web integration of plots and it's the cleanest design out there in my opinion. I have also looked at Bokeh and python-nvd3 but none are as intuitive as vincent/vega when you have used ggplot2 before.

networkx integration

This seems an odd place to start talking about this but I couldn't find mention of a mailing list anywhere.

First of all, props for an intuitive design and neat looking code, very Pythonic!

I've been looking around for a good interaction between networkx and D3.js for a while now and noticed that others have also done so. Yes, I can dump a graph to JSON and simply load it again but there are two things I would like to be able to do:

  1. I'm an IPython Notebook user and vincent already has some neat interaction going. I would like to leverage that.
  2. Building on top of that experience, I would like to build a server that accepts input of some form and allows interaction between Python code that manipulates the graph and a reflection of the visualization on the server (similar to what ubigraph used to do). The server should then allow manipulation of all relevant display parameters.

What do you think, does this (at least point 1) fit into the vincent framework and if so can you point me towards implementing that?

Error during import

I get this error during import.

import vincent
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/site-packages/vincent-0.3.0-py2.6.egg/vincent/init.py", line 12, in
from .charts import (Chart, Bar, Line, Area, Scatter, StackedBar, StackedArea,
File "/usr/lib/python2.6/site-packages/vincent-0.3.0-py2.6.egg/vincent/charts.py", line 8, in
from .visualization import Visualization
File "/usr/lib/python2.6/site-packages/vincent-0.3.0-py2.6.egg/vincent/visualization.py", line 11, in
from .data import Data
File "/usr/lib/python2.6/site-packages/vincent-0.3.0-py2.6.egg/vincent/data.py", line 360
data = {x: y for x, y in enumerate(data)}
^
SyntaxError: invalid syntax

Can't make bar plot from Pandas timeseries

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)

Inline graphics not displaying in python notebook

Hello,

I have been trying to somehow have the output of the vincent graphs show up in ipython notebook to no avail. I don't see any error messages neither on output of notebook nor on the notebook console.

I am using Mavericks with Python 2.7.6 and vincent version 0.4 installed using pip.

Below is a sample snippet that I used:

import vincent

list_data = [10, 20, 30, 20, 15, 30, 45]

vincent.core.initialize_notebook()

bar = vincent.Bar(list_data)
bar.axis_titles(x='Index', y='Value')
bar.display()

A few missing dependencies

Looks like vincent has dependencies also to pkgtools and thus indirectly setuptools. Would be at least worth mentioning in the installation parts along with pandas dependency.

IPython dependency

Hey, first off, great work on this project, it's been a joy to use. I've got kind of a 2 part issue here. I tried deploying an application using vincent to heroku, and to my surprise found that my application was crashing because vincent attempts to make imports against ipython when it is loaded. Since ipython is not listed as a requirement in setup.py, it wasn't installed by pip, and hence my problem.

So, I normally might just submit a pull with ipython added to the requirements, but ... is there any real reason for ipython to be a requirement? I'm not using any of the ipython integration features in my application, so it seems silly that it should be a dependency. Consequently, I'd suggest that the imports from the ipython integration module be removed from __init__.py ... but perhaps you guys have reasons to keep it there. Just thought I'd bring it up. Thanks!

Add Example for Map with Points

I would love to see an example which uses topojson points. I struggled trying to make this work and kept getting errors in vega. Maybe just not possible currently?

My fix was to skip Vincent+Vega and use topojson with D3 directly, but it sure would be nice to be able to do this with Vincent and Vega.

Feature Request: make output display inline in IPython notebooks

My usual workflow has become heavily dependent on the IPython notebook. It would be great for me to be able to develop vega visualizations with vincent using this approach.

I don't think it will be that difficult to implement this. Perhaps the vis.to_json() methods could be extended to return a string if it is not given a file name, and then it is just a matter of doing some plumbing to turn this into an IPython.core.display.Javascript or .HTML object.

I'll give it a try, and if it works I can send a PR, if you are interested.

Index out of range with 'Vega.tabular_data()' and pd.DateTimeIndex

Hi,

Commit 5200e3d seems introduce the error in the method update_component at the line:

parameter = getattr(self, parameter)[index]

when parameter is 'scales for instance, it can be an empty list. This happens when the data passed to the tabular_data has a pandas.DateTimeIndex (see the inner function period_axis).

I'm trying to write a test case for this.

Best regards,
Damien G.

TopoJSON library not loading in IPython notebook

I've not been able to get vincent to display a world map, either within an IPython notebook or in a standalone HTML file.

The notebook I'm running: http://nbviewer.ipython.org/gist/rdhyee/8656332

I'm running the following environment:

Mac OS X 10.6.8
Python 2.7.5 :: Anaconda 1.8.0 (x86_64)
Chrome Version 32.0.1700.77 (and Firefox 26.0 -- same error)
IPython 1.1
Vincent 0.4.3

All the vincent examples work except the world map. I get the error:

TopoJSON library not loaded

The standalone HTML file gives a similar error. When I load vincent_world_map.html -- I don't see a map. I see in JS console: "Uncaught TypeError: Cannot read property 'world-countries' of undefined "

vg2png does not produce a png as sized by width, hight and viewport

I'm making some choropleth maps and when using vg2png it show the full region of the map projection.

I am trying to zoom in to a particular region by using the scale and translate parameters, but this just seems to alter where on the canvas the map gets placed. The full map is always generated.

Replace display_vega by IPython.display

We (IPython) are encouraging projects to not invent their own functions that display things in the notebook. Instead, they should define special display methods on their objects such as _repr_html_ and use the IPython display function.

However, display_vega needs to display both HTML and JavaScript in a single call and our display architecture is not setup to handle that. One thing that I have been thinking about is to change how IPython handles objects with both HTML and JavaScript output. @minrk what do you think about having the Notebook first put the HTML on the page and then running the JavaScript - IOW making those display types handled using AND rather than OR...

Add numpy array support to tabular_data

It would be nice to have support for instances of numpy.ndarray instead of having to rely on pandas.DataFrame. This would extend vincent to work with some non-statistical applications, like simulations or stuff imported from Matlab.

I've got a branch in the works for this, so I'm just throwing this issue out there for comments. It's coming along well, but I'm not sure when it'll be finished, so not sure if it should go in v1 or not.

I'd like to see vincent get to the point where it's a viable replacement for matplotlib. I think it would get surprisingly close to reproducing most of the functionality with this change.

Error on the "Built from Scratch"

Hey everyone,

I copied and paste the code of the "Built from Scratch" to try the library.

The program fails with exit code -1073741819 and from the debug, I saw it doesn't pass the "#Data. We're going to key Data 2 on Data 1".

I'm running on Windows 8.1.

My modules installed with pip are:

distribute (0.7.3)
numpy (1.7.2)
pandas (0.13.0)
pip (1.5)
python-dateutil (2.2)
pytz (2013.9)
requests (2.2.0)
setuptools (2.1)
six (1.5.2)
vincent (0.4.1)
virtualenv (1.11)

If you guys had any ideas, it could be great,
Thank you in advance.
Alexis.
PS: I don't know if it helps but I couldn't install numpy with pip intall, I had to install it with a .exe

ENH: add and sub return new object

Are you absolutely committed to the vis + (...) syntax?

It could be useful for the statements

vis1 = vis + (some stuff)
vis2 = vis + (some more stuff)

and

vis2 = vis + (some more stuff)
vis1 = vis + (some stuff)

to produce the same result.

Seems like it would be simple enough to implement. I could probably have a PR by mid-week.

Limitations without Pandas/NumPy dependencies?

This seems like a great alternative interaction model for Vega/D3.js.
At the end of the Readme, there is a PSA stating that certain functionality in Vincent can be used without Pandas/NumPy. I wonder if you could elaborate on the limitations?

Running the vega bar tutorial gives an error

I thought this would run the "examples" run fine...
In [24]:

vis.display()
Javascript error adding output!
ReferenceError: vg is not defined
See your browser Javascript console for more details.
JS console>>>>
Starting WebSockets: ws://127.0.0.1:8888/kernels/6f1df49e-bfc5-4322-8df3-7fc6e610ad77 kernel.js:143
Failed to load resource: the server responded with a status of 404 (Not Found) http://trifacta.github.io/vega/d3.v3.min.js?_=1380837468348
Failed to load resource: the server responded with a status of 404 (Not Found) http://trifacta.github.io/vega/d3.v3.min.js?_=1380837468350
Failed to load resource: the server responded with a status of 404 (Not Found) http://trifacta.github.io/vega/d3.v3.min.js?_=1380837468348
Failed to load resource: the server responded with a status of 404 (Not Found) http://trifacta.github.io/vega/d3.v3.min.js
Failed to load resource: the server responded with a status of 404 (Not Found) http://trifacta.github.io/vega/d3.v3.min.js?_=1380837468350
Uncaught ReferenceError: d3 is not defined trifacta.github.io/vega/vega.js?=1380837468349:7039
Uncaught ReferenceError: d3 is not defined trifacta.github.io/vega/vega.js?
=1380837468351:7039
Javascript error adding output!
ReferenceError
outputarea.js:319
Kernel started: 6f1df49e-bfc5-4322-8df3-7fc6e610ad77 kernel.js:110
Starting WebSockets: ws://127.0.0.1:8888/kernels/6f1df49e-bfc5-4322-8df3-7fc6e610ad77 kernel.js:143
Javascript error adding output!
ReferenceError
outputarea.js:319
Javascript error adding output!
ReferenceError

to_json() method

to_json() method currently accepts a filename, wouldn't it be a cleaner solution to be able to pass it a generic stream?

Possibility to update charts in IPython Notebook

Is it possible to update a chart in the IPython Notebook?
This is very useful if you are running simulations to see your simulation evolve.

e.g.

array = [10, 20, 30, 20, 15, 30, 45]

line = vincent.Line(array)
line.display()
for x in range(1, 10):
line.data = (x*array)
line.display()

Would display one plot that would continue to scale. (Now displays 9 plots)

Install issue

the file "vega_template.html" are not installed in "dist-packages/vincent/" by default,

I try using pip and setup.py in zip file

To fix i used
$ sudo cp vega_template.html /[path_to]/dist-packages/vincent/

Datetime indexed dataframe as data for tabular_data() - with Vega() visualisation

I have run into an issue. When I use the Line() class everything is fine. Although I did have to change the imports (i.e. different than your blog example).

import pandas as pd
import vincent
from vincent import ipynb
ipynb.init_d3()
ipynb.init_vg()
import pandas.io.data as web
all_data = {}
ticker = 'GOOG'
all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2010', '1/1/2013')
price = pd.DataFrame({tic: data['Adj Close']
                      for tic, data in all_data.iteritems()})
vis = vincent.Line()
vis.tabular_data(price, columns=['GOOG'], axis_time='day')
ipynb.display_vega(vis)

Works beautifully (is it too late to say thanks for this library?).
However, I wanted to build a visualisation from scratch, i.i using the base Vega() class. But I get the following trace back. Presumeably, it is trying to update a key that doesn't exist in the base but is added by subclassing when you create Bar and/or Line? Or am I doing it wrong?

vis = vincent.Vega()
vis.tabular_data(price, columns=['GOOG'], axis_time='day')
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-29-971fe554a67c> in <module>()
      1 vis = vincent.Vega()
----> 2 vis.tabular_data(price, columns=['GOOG'], axis_time='day')

C:\Python27\lib\site-packages\vincent\vincent.pyc in tabular_data(self, data, columns, use_index, append, axis_time)
    441                                  'cannot be > 1')
    442             if use_index or len(columns) == 1:
--> 443                 period_axis(data, axis_time)
    444                 values = [{"x": x[0], "y": x[1][columns[0]]}
    445                           for x in data.iterrows()]

C:\Python27\lib\site-packages\vincent\vincent.pyc in period_axis(data, axis_time)
    410             if isinstance(data.index, pd.DatetimeIndex):
    411                 self.update_component('add', 'time', 'scales', 0,
--> 412                                       'type')
    413                 self.update_component('add', axis_time, 'scales', 0,
    414                                       'nice')

C:\Python27\lib\site-packages\vincent\vincent.pyc in update_component(self, change, value, parameter, index, *args)
    277                 param[key].pop(value)
    278 
--> 279         parameter = getattr(self, parameter)[index]
    280         if not args:
    281             args = [value]

IndexError: list index out of range

Make update_component() signature more intuitive

As it stands, vincent.py has the following method:

def update_component(self, change, value, parameter, index, *args):
    '''Update individual parameters of any component.

    Parameters:
    -----------
    change: string, either 'add' or 'remove'
    'add' will add the value to the last specified key in *args (this
    can be a new key). 'remove' will remove the key specified by
    'value'.
    value: Any JSON compatible datatype
    The value you want to substitute into the component
    parameter: string
    The Vega component you want to modify (scales, marks, etc)
    index: int
    The index of dict/object in the component array you want to mod

    Examples:
    >>>my_vega.update_component('add', 'w', 'axes', 0, 'scale')
    >>>my_vega.update_component('remove', 'width', 'marks', 0,
    'properties', 'enter')

    '''

Its signature is awkward. Specifically, the order of the arguments requires one to mentally traverse the Vega spec tree from two directions, top-down and bottom-up.

I propose the following more intuitive signature:

def update_component(self, *args)

where args is a tuple of strings of length at least 3 that firstly specifies the Vega tree leaf to update in depth-first order in the Vega spec tree, secondly specifies what type of change to make, and thirdly specifies the change value.

For example, in the new signature the two examples above would be written

 >>>my_vega.update_component('axes', 0, 'scale', 'add', 'w')
 >>>my_vega.update_component('marks', 0, 'properties', 'enter', 'remove', 'width')

Does that make sense?

interactivity?

Just a question:
how are your plans in supporting interactivity?

  • zoom
  • hover and show data points
  • pan

Dict comprehension in Python2.6 !

There is a different way to write dict comprehension in python 2.6, because which line number 343 in data.py throws an error.

The correct way that I could figure out is

Python 2.6

data = dict((x,y) for x, y in enumerate(data)) instead of

Python 2.7+

data = {x: y for x, y in enumerate(data)}

Let me know how do I push this.Keeping it version agnostic.

Broken url handling in Map plotting

As far as I can tell, neither 0.3 or master successfully load topo JSON data. Happy to help with more information on this, but I'm not really sure where the problem is arising. I get a javascript popup error from Vega itself: "LOADING FAILED ", where loads just fine in my browser. I also tried file paths relative to the ipython notebook server, this also doesn't work.

Issue with iPython Integration

vincent_bug
In the following attachment, I have shown the code that is used in the quickstart guide (specifically the section on iPython integration). Nothing happens when I use .display(), but I see JS errors. The first one states "require is not defined", followed by messages about missing D3.js. I assume require.js is not loading? If there is a better place to be asking this, please let me know and I'll post there.

Info:

$ ipython --version
0.13

Using vincent-0.4.2-py2.7.egg-info in /usr/local/lib/python2.7/dist-packages on Ubuntu 13.

Notebook example not working in ipython 1.0dev

Testing vincent with the latest version of ipython from github (1.0dev) fails with the following error:

Error in Javascript !
ReferenceError: vg is not defined
See your browser Javascript console for more details.

On inspection, this is where the failure comes from:
[21:11:24.045] (new ReferenceError("vg is not defined", "http://127.0.0.1:8888/static/js/outputarea.js", 363))

Which makes it appear like the vega.js library isn't being loaded. However, if I dump the .ipynb file to html, the <script> tags are clearly there.

I switched to the current official release and the ipynb example rendered correctly.

BUG: Negative data not displayed on line plot

The following

import vincent
vis = vincent.Line()
y = [0, 3, 4, 1, 0, -4, -5]
vis.tabular_data(y)
vis.axis_label(x_label='Time', y_label='Data')
vis.to_json('data.json')

produces a JSON file that plots the negative numbers as 0. This seems to be being caused by "y2" under marks->properties->enter being 0. It looks like just removing this should have it plot correctly. Is there a reason to keep the y2=0 default?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.