{"id":13416303,"url":"https://github.com/wrobstory/vincent","last_synced_at":"2025-10-21T20:14:39.880Z","repository":{"id":7962546,"uuid":"9360778","full_name":"wrobstory/vincent","owner":"wrobstory","description":"A Python to Vega translator","archived":true,"fork":false,"pushed_at":"2016-10-25T18:56:07.000Z","size":7081,"stargazers_count":2037,"open_issues_count":42,"forks_count":227,"subscribers_count":90,"default_branch":"master","last_synced_at":"2024-10-29T23:18:44.513Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wrobstory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-11T02:44:53.000Z","updated_at":"2024-08-19T14:15:49.000Z","dependencies_parsed_at":"2022-08-05T23:15:09.035Z","dependency_job_id":null,"html_url":"https://github.com/wrobstory/vincent","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrobstory%2Fvincent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrobstory%2Fvincent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrobstory%2Fvincent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrobstory%2Fvincent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wrobstory","download_url":"https://codeload.github.com/wrobstory/vincent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234575214,"owners_count":18854924,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:56.735Z","updated_at":"2025-09-28T23:32:24.947Z","avatar_url":"https://github.com/wrobstory.png","language":"Python","funding_links":[],"categories":["Data Visualization","Python","资源列表","others"],"sub_categories":["数据可视化","General-Purpose Machine Learning"],"readme":"# Status\n\n#### 2016-06-18 Update\n\nIf 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. \n\nThere 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. \n\n#Vincent\n\n[![Travs-CI status](https://travis-ci.org/wrobstory/vincent.png)](https://travis-ci.org/wrobstory/vincent)\n\n![Vincent](http://farm9.staticflickr.com/8521/8644902478_0d1513db92_o.jpg)\n\n###A Python to Vega translator\n\nThe 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.\n\nConcept\n-------\nThe data capabilities of Python. The visualization capabilities of JavaScript.\n\nVincent takes Python data structures and translates them into [Vega](https://github.com/trifacta/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.\n\nPerhaps most importantly, Vincent groks Pandas DataFrames and Series in an intuitive way.\n\nInstallation\n------------\n\n```$pip install vincent```\n\nWarning: 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](http://www.continuum.io/downloads).\n\nDocs\n----\n\n[Here.](https://vincent.readthedocs.org/en/latest/)\n\nQuickstart\n---------------\n\nLet's start with some varying [data](https://vincent.readthedocs.org/en/latest/quickstart.html#data), and then show some different ways to visualize them with Vincent.\n\nStarting with a simple bar chart:\n\n```python\nimport vincent\nbar = vincent.Bar(multi_iter1['y1'])\nbar.axis_titles(x='Index', y='Value')\nbar.to_json('vega.json')\n```\n\n![bars](http://farm4.staticflickr.com/3720/9388500423_b3493bbba7_o.jpg)\n\nPlotting a number of lines:\n\n```python\nline = vincent.Line(multi_iter1, iter_idx='index')\nline.axis_titles(x='Index', y='Value')\nline.legend(title='Categories')\n```\n\n![lines](http://farm6.staticflickr.com/5543/9388500445_0bdf2a22e3_o.jpg)\n\nOr a real use case, plotting stock data:\n\n```python\nline = vincent.Line(price[['GOOG', 'AAPL']])\nline.axis_titles(x='Date', y='Price')\nline.legend(title='GOOG vs AAPL')\n```\n\n![stocks1](http://farm4.staticflickr.com/3774/9391272680_67e323de24_o.jpg)\n\nColor brewer scales are built-in. For example, plotting a scatter plot with the ```Set3``` colors:\n\n```python\nscatter = vincent.Scatter(multi_iter2, iter_idx='index')\nscatter.axis_titles(x='Index', y='Data Value')\nscatter.legend(title='Categories')\nscatter.colors(brew='Set3')\n```\n\n![scatter](http://farm6.staticflickr.com/5341/9391272876_724d5fca0d_o.jpg)\n\nArea charts:\n\n```python\narea = vincent.Area(list_data)\n```\n\n![area](http://farm3.staticflickr.com/2825/9388500487_b7c1a67771_o.jpg)\n\nStacked Area Charts from a DataFrame:\n```python\nstacked = vincent.StackedArea(df_1)\nstacked.axis_titles(x='Index', y='Value')\nstacked.legend(title='Categories')\nstacked.colors(brew='Spectral')\n```\n\n![areastack](http://farm4.staticflickr.com/3827/9388500389_88ca0f0e5f_o.jpg)\n\n```python\nstacked = vincent.StackedArea(price)\nstacked.axis_titles(x='Date', y='Price')\nstacked.legend(title='Tech Stocks')\n```\n![areastack2](http://farm8.staticflickr.com/7355/9388540267_823111c78d_o.jpg)\n\nStacked Bar Charts from a DataFrame:\n\n```python\nstack = vincent.StackedBar(df_2)\nstack.legend(title='Categories')\nstack.scales['x'].padding = 0.1\n```\n![barstack1](http://farm6.staticflickr.com/5528/9391272710_c92d21da11_o.jpg)\n\n```python\nstack = vincent.StackedBar(df_farm.T)\nstack.axis_titles(x='Total Produce', y='Farms')\nstack.legend(title='Produce Types')\nstack.colors(brew='Pastel1')\n```\n![barstack2](http://farm4.staticflickr.com/3784/9388530799_623084dbe0_o.jpg)\n\nGrouped Bars from a DataFrame:\n\n```python\ngroup = vincent.GroupedBar(df_2)\ngroup.legend(title='Categories')\ngroup.colors(brew='Spectral')\ngroup.width=750\n```\n![groupbar1](http://farm6.staticflickr.com/5507/9388500521_1ec446c0e9_o.jpg)\n\n```python\ngroup = vincent.GroupedBar(df_farm)\ngroup.axis_titles(x='Total Produce', y='Farms')\ngroup.legend(title='Produce Types')\ngroup.colors(brew='Set2')\n```\n![groupbar2](http://farm6.staticflickr.com/5518/9391272912_706055754a_o.jpg)\n\nPie charts:\n\n```python\nvis = vincent.Pie(farm_1)\nvis.legend('Farm 1 Fruit')\n```\n![pie](https://farm4.staticflickr.com/3684/11391908745_227ffba829.jpg)\n\nDonut charts:\n\n```\nvis = vincent.Pie(farm_1, inner_radius=200)\nvis.colors(brew=\"Set2\")\nvis.legend('Farm 1 Fruit')\n```\n![donut](http://farm6.staticflickr.com/5530/11391917226_598fbdf3e2.jpg)\n\nSimple maps can be built quickly (all data can be found in the [vincent_map_data](https://github.com/wrobstory/vincent_map_data) repo):\n\n```python\nworld_topo = r'world-countries.topo.json'\ngeo_data = [{'name': 'countries',\n             'url': world_topo,\n             'feature': 'world-countries'}]\n\nvis = vincent.Map(geo_data=geo_data, scale=200)\n```\n\n![simplemap](http://farm3.staticflickr.com/2852/10140081393_fa46545724_c.jpg)\n\nAlso with multiple map layers:\n\n```python\ngeo_data = [{'name': 'counties',\n             'url': county_topo,\n             'feature': 'us_counties.geo'},\n            {'name': 'states',\n             'url': state_topo,\n             'feature': 'us_states.geo'}]\n\nvis = vincent.Map(geo_data=geo_data, scale=1000, projection='albersUsa')\ndel vis.marks[1].properties.update\nvis.marks[0].properties.update.fill.value = '#084081'\nvis.marks[1].properties.enter.stroke.value = '#fff'\nvis.marks[0].properties.enter.stroke.value = '#7bccc4'\n\n```\n\n![multiplelayer](http://farm4.staticflickr.com/3797/10140037456_8256fbd32d_c.jpg)\n\nMaps can be bound with data to Pandas DataFrames for choropleth visualizations (see [here](https://vincent.readthedocs.org/en/latest/quickstart.html#data) for map data munging):\n\n```python\ngeo_data = [{'name': 'counties',\n             'url': county_topo,\n             'feature': 'us_counties.geo'}]\n\nvis = vincent.Map(data=merged, geo_data=geo_data, scale=1100, projection='albersUsa',\n          data_bind='Unemployment_rate_2011', data_key='FIPS',\n          map_key={'counties': 'properties.FIPS'})\nvis.marks[0].properties.enter.stroke_opacity = ValueRef(value=0.5)\nvis.to_json('vega.json')\n```\n\n![binding1](http://farm8.staticflickr.com/7414/10139958645_681c6dd006_c.jpg)\n\nIt can be rebound on the fly with new data and color brewer scales:\n\n```python\nvis.rebind(column='Median_Household_Income_2011', brew='YlGnBu')\n```\n\n![binding2](http://farm3.staticflickr.com/2833/10140081893_4f5fa762c5_c.jpg)\n\n\nFor more examples, including how to build these from scratch, see the [examples](https://github.com/wrobstory/vincent) directory, or the [docs](https://vincent.readthedocs.org/en/latest/index.html).\n\n\nBuilt from Scratch\n------------------\n\nTo see how the charts are being built with Vincent -\u003e Vega grammar, see the ```charts.py``` module.\n\nBuilding the bar chart from scratch will provide a quick example of building with Vincent:\n\n```python\nimport pandas as pd\nfrom vincent import (Visualization, Scale, DataRef, Data, PropertySet,\n                     Axis, ValueRef, MarkRef, MarkProperties, Mark)\n\ndf = pd.DataFrame({'Data 1': [15, 29, 63, 28, 45, 73, 15, 62],\n                   'Data 2': [42, 27, 52, 18, 61, 19, 62, 33]})\n\n#Top level Visualization\nvis = Visualization(width=500, height=300)\nvis.padding = {'top': 10, 'left': 50, 'bottom': 50, 'right': 100}\n\n#Data. We're going to key Data 2 on Data 1\nvis.data.append(Data.from_pandas(df, columns=['Data 2'], key_on='Data 1', name='table'))\n\n#Scales\nvis.scales.append(Scale(name='x', type='ordinal', range='width',\n                        domain=DataRef(data='table', field=\"data.idx\")))\nvis.scales.append(Scale(name='y', range='height', nice=True,\n                        domain=DataRef(data='table', field=\"data.val\")))\n\n#Axes\nvis.axes.extend([Axis(type='x', scale='x'), Axis(type='y', scale='y')])\n\n#Marks\nenter_props = PropertySet(x=ValueRef(scale='x', field=\"data.idx\"),\n                                     y=ValueRef(scale='y', field=\"data.val\"),\n                                     width=ValueRef(scale='x', band=True, offset=-1),\n                                     y2=ValueRef(scale='y', value=0))\nupdate_props = PropertySet(fill=ValueRef(value='steelblue'))\nmark = Mark(type='rect', from_=MarkRef(data='table'),\n            properties=MarkProperties(enter=enter_props,\n            update=update_props))\n\nvis.marks.append(mark)\nvis.axis_titles(x='Data 1', y='Data 2')\nvis.to_json('vega.json')\n```\n![barscratch](http://farm3.staticflickr.com/2866/9341688818_c154660c3f_o.jpg)\n\nBecause the Vega elements are represented by Python classes, it can be difficult to get a good idea of what the Vega grammar looks like:\n```python\nIn [5]: vis.marks[0]\n\u003cvincent.marks.Mark at 0x110d630d0\u003e\n```\n\nHowever, at almost any point in the Vincent stack, you can call the ```grammar()``` method to output the Vega grammar as Python data structures:\n\n```python\n\u003e\u003e\u003evis.marks[0].grammar()\n{u'from': {u'data': u'table'},\n u'properties': {u'enter': {u'width': {u'band': True,\n    u'offset': -1,\n    u'scale': u'x'},\n   u'x': {u'field': u'data.idx', u'scale': u'x'},\n   u'y': {u'field': u'data.val', u'scale': u'y'},\n   u'y2': {u'scale': u'y', u'value': 0}},\n  u'update': {u'fill': {u'value': u'steelblue'}}},\n u'type': u'rect'}\n\u003e\u003e\u003evis.marks[0].properties.enter.x.grammar()\n{u'field': u'data.idx', u'scale': u'x'}\n```\n\nor you can simply output it to a string of JSON:\n```python\n\u003e\u003e\u003eprint(vis.marks[0].to_json())\n{\n  \"type\": \"rect\",\n  \"from\": {\n    \"data\": \"table\"\n  },\n  \"properties\": {\n    \"update\": {\n      \"fill\": {\n        \"value\": \"steelblue\"\n      }\n    },\n    \"enter\": {\n      \"y\": {\n        \"field\": \"data.val\",\n        \"scale\": \"y\"\n      },\n      \"width\": {\n        \"band\": true,\n        \"scale\": \"x\",\n        \"offset\": -1\n      },\n      \"y2\": {\n        \"scale\": \"y\",\n        \"value\": 0\n      },\n      \"x\": {\n        \"field\": \"data.idx\",\n        \"scale\": \"x\"\n      }\n    }\n  }\n}\n```\n\nVincent is built around classes and attributes that map 1:1 to Vega grammar, for easy getting, setting,\nand deleting of grammar elements:\n\n```python\n\u003e\u003e\u003evis.marks[0].properties.enter.grammar()\n{u'width': {u'band': True, u'offset': -1, u'scale': u'x'},\n u'x': {u'field': u'data.idx', u'scale': u'x'},\n u'y': {u'field': u'data.val', u'scale': u'y'},\n u'y2': {u'scale': u'y', u'value': 0}}\n \u003e\u003e\u003e del vis.marks[0].properties.enter.width\n \u003e\u003e\u003e vis.marks[0].properties.enter.y2.scale = 'y2'\n \u003e\u003e\u003e vis.marks[0].properties.enter.grammar()\n{u'x': {u'field': u'data.idx', u'scale': u'x'},\n u'y': {u'field': u'data.val', u'scale': u'y'},\n u'y2': {u'scale': u'y2', u'value': 0}}\n```\n\nContributors\n------------\nHuge thanks to all who have contributed to Vincent development:\n\n * Rob Story (wrobstory)\n * Dan Miller (dnmiller)\n * Peter Lubell-Doughtie (pld)\n * Lx Yu (lxyu)\n * Damien Garaud (garaud)\n * Abraham Flaxman (aflaxman)\n * Mahdi Yusuf (myusuf3)\n * Richard Maisano (maisano)\n * Julian Berman (Julian)\n * Chris Rebert (cvrebert)\n * Wojciech Bederski (wuub)\n * Min RK (minrk)\n * Drazen Lucanin (kermit666)\n * tlukasiak\n\n\nDependencies\n------------\n\n * pandas\n * pkgtools\n\nTesting:\n\n * mock\n * nose\n\nPSA: you can use pieces of Vincent without Pandas, but its tricky. Besides, Pandas is awesome- try it!\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwrobstory%2Fvincent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwrobstory%2Fvincent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwrobstory%2Fvincent/lists"}