{"id":13720603,"url":"https://github.com/vegas-viz/Vegas","last_synced_at":"2025-05-07T12:31:49.406Z","repository":{"id":44693929,"uuid":"56254047","full_name":"vegas-viz/Vegas","owner":"vegas-viz","description":"The missing MatPlotLib for Scala + Spark","archived":false,"fork":false,"pushed_at":"2022-01-30T23:39:05.000Z","size":888,"stargazers_count":730,"open_issues_count":54,"forks_count":98,"subscribers_count":41,"default_branch":"master","last_synced_at":"2024-12-28T07:07:48.154Z","etag":null,"topics":["datascience","plotting","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/vegas-viz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-14T16:44:32.000Z","updated_at":"2024-09-01T21:17:45.000Z","dependencies_parsed_at":"2022-09-16T14:50:15.550Z","dependency_job_id":null,"html_url":"https://github.com/vegas-viz/Vegas","commit_stats":null,"previous_names":["aishfenton/vegas"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegas-viz%2FVegas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegas-viz%2FVegas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegas-viz%2FVegas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegas-viz%2FVegas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vegas-viz","download_url":"https://codeload.github.com/vegas-viz/Vegas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252876445,"owners_count":21818181,"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":["datascience","plotting","scala"],"created_at":"2024-08-03T01:01:05.760Z","updated_at":"2025-05-07T12:31:44.396Z","avatar_url":"https://github.com/vegas-viz.png","language":"Scala","funding_links":[],"categories":["Scala","数据科学","Big Data","Wrappers"],"sub_categories":["计算机视觉","Papers"],"readme":"# Vegas \n\n\u003cimg src=\"https://www.vegas-viz.org/images/logo.png\" alt=\"Vegas\" width=\"250px\"\u003e\n\n[![TravisCI](https://travis-ci.org/vegas-viz/Vegas.svg?branch=master)](https://travis-ci.org/vegas-viz/Vegas)\n[![codecov](https://codecov.io/gh/vegas-viz/Vegas/branch/master/graph/badge.svg)](https://codecov.io/gh/vegas-viz/Vegas)\n\nVegas aims to be the missing MatPlotLib for the Scala and Spark world. Vegas wraps around [Vega-Lite](https://vega.github.io/vega-lite/) but provides syntax more familiar (and type checked) for use within Scala.\n\n\u003cimg src=\"https://www.vegas-viz.org/images/gallery.png?true\" width=\"1021\"\u003e\n\n## Quick start\n\nAdd the following jar as an SBT dependency\n\n```sbt\nlibraryDependencies += \"org.vegas-viz\" %% \"vegas\" % {vegas-version}\n```\n\nAnd then use the following code to render a plot into a pop-up window (see below for more details on controlling how and where Vegas renders).\n\n```scala\nimport vegas._\nimport vegas.render.WindowRenderer._\n\nval plot = Vegas(\"Country Pop\").\n  withData(\n    Seq(\n      Map(\"country\" -\u003e \"USA\", \"population\" -\u003e 314),\n      Map(\"country\" -\u003e \"UK\", \"population\" -\u003e 64),\n      Map(\"country\" -\u003e \"DK\", \"population\" -\u003e 80)\n    )\n  ).\n  encodeX(\"country\", Nom).\n  encodeY(\"population\", Quant).\n  mark(Bar)\n\nplot.show\n```\n\n![\"Readme Chart 1\"](https://www.vegas-viz.org/images/readme-chart-1.png)\n\nSee further examples [here](http://nbviewer.jupyter.org/github/aishfenton/Vegas/blob/master/notebooks/jupyter_example.ipynb)\n\n## Rendering\n\nVegas provides several options for rendering plots. The primary focus is using Vegas within interactive notebook environments, such as Jupyter and Zeppelin.\nRendering is provided via an implicit instance of `ShowRender`, which tells Vegas how to display the plot in a particular environment. The default instance\nof `ShowRender` uses a macro which attempts to guess your environment, but if for some reason that fails, you can specify your own instance:\n\n```scala\n// for outputting HTML, provide a function String =\u003e Unit which will receive the HTML for the plot\n// and use vegas.render.ShowHTML to create an instance for it\nimplicit val renderer = vegas.render.ShowHTML(str =\u003e println(s\"The HTML is $str\"))\n\n// to specify a function that receives the SpecBuilder instead, use vegas.render.ShowRender.using\nimplicit val renderer = vegas.render.ShowRender.using(sb =\u003e println(s\"The SpecBuilder is $sb\"))\n```\n\nThe following examples describe some common cases; these *should* be handled by the default macro, but are useful to\nsee (in case you need to construct your own instance of `ShowRender`):\n\n### Notebooks\n\n#### Jupyter - Scala\n\nIf you're using [jupyter-scala](https://github.com/alexarchambault/jupyter-scala), then can include the following in your notebook before using Vegas.\n\n```scala\nimport $ivy.`org.vegas-viz::vegas:{vegas-version}`\n```\n\n```scala\nimplicit val render = vegas.render.ShowHTML(publish(_))\n``` \n\n#### Jupyter - Apache Toree\n\nAnd if you're using [Apache Toree](https://toree.incubator.apache.org/), then this:\n\n```\n%AddDeps org.vegas-viz vegas_2.11 {vegas-version} --transitive\n```\n\n```scala\nimplicit val render = vegas.render.ShowHTML(kernel.display.content(\"text/html\", _))\n``` \n\n#### Zeppelin\n\nIf you're using [Apache Zeppelin](https://zeppelin.incubator.apache.org/):\n\n```\n%dep\nz.load(\"org.vegas-viz:vegas_2.11:{vegas-version}\")\n```\n```scala\nimplicit val render = vegas.render.ShowHTML(s =\u003e print(\"%html \" + s))\n```\n\nThe last line in each of the above is required to connect Vegas to the notebook's HTML renderer (so that the returned HTML is rendered instead of displayed as a string). \n\nSee a comprehensive list example notebook of plots  [here](http://nbviewer.jupyter.org/github/aishfenton/Vegas/blob/master/notebooks/jupyter_example.ipynb)\n\n### Standalone\n\nVegas can also be used to produce standalone HTML or even render plots within a built-in display app (useful if you wanted to display plots for a command-line-app). \n\nThe construction of the plot is **independent from the rendering strategy**: the same plot can be rendered as HTML or in a Window simply by importing a different renderer in the scope. \n\n*Note that the rendering examples below are wrapped in separate functions to avoid ambiguous implicit conversions if they were imported in the same scope.*\n\nA plot is defined as:\n\n```scala\nimport vegas._\n\nval plot = Vegas(\"Country Pop\").\n  withData(\n    Seq(\n      Map(\"country\" -\u003e \"USA\", \"population\" -\u003e 314),\n      Map(\"country\" -\u003e \"UK\", \"population\" -\u003e 64),\n      Map(\"country\" -\u003e \"DK\", \"population\" -\u003e 80)\n    )\n  ).\n  encodeX(\"country\", Nom).\n  encodeY(\"population\", Quant).\n  mark(Bar)\n```\n\n#### HTML\n\nThe following renders the plot as HTML (which prints to the console).\n\n```scala\ndef renderHTML = {\n  println(plot.html.pageHTML) // a complete HTML page containing the plot\n  println(plot.html.frameHTML(\"foo\")) // an iframe containing the plot\n}\n```\n\n#### Window\n\nVegas also contains a self-contained display app for displaying plots (internally it uses JavaFX's HTML renderer). The following demonstrates this and can be used from the command line. \n\n```scala\ndef renderWindow = {\n  plot.window.show\n}\n```\n\nMake sure JavaFX is installed on your system or ships with your JDK distribution.\n\n#### JSON \n\nYou can print the JSON containing the Vega-lite spec, without importing any renderer in the scope.\n\n```scala\nprintln(plot.toJson)\n```\n\nThe output JSON can be copy-pasted into the Vega-lite [editor](https://vega.github.io/vega-editor/?mode=vega-lite\u0026spec=bar).\n\n## Spark integration\n\nVegas comes with an optional extension package that makes it easier to work with Spark DataFrames. First, you'll need an extra import\n\n```sbt\nlibraryDependencies += \"org.vegas-viz\" %% \"vegas-spark\" % \"{vegas-version}\"\n```\n\n```scala\nimport vegas.sparkExt._\n```\n\nThis adds the following new method:\n\n```scala\nwithDataFrame(df: DataFrame)\n```\n\nEach DataFrame column is exposed as a field keyed using the column's name.\n\n## Flink integration\n\nVegas also comes with an optional extension package that makes it easier to work with Flink DataSets. You'll also need to import:\n```sbt\nlibraryDependencies += \"org.vegas-viz\" %% \"vegas-flink\" % \"{vegas-version}\"\n```\n\nTo use:\n```scala\nimport vegas.flink.Flink._\n```\n\nThis adds the following method:\n\n```scala\nwithData[T \u003c: Product](ds: DataSet[T])\n```\nSimilarly, to the RDD concept in Spark, a DataSet of _case classes_ or _tuples_ is expected and reflection is used to map the case class' fields to fields within Vegas. In the case of tuples you can encode the fields using `\"_1\", \"_2\"` and so on.\n\n## Plot Options\n\nTODO\n\n## Contributing\n\nSee [the contributing guide](CONTRIBUTING.md) for more information on contributing bug fixes and features.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvegas-viz%2FVegas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvegas-viz%2FVegas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvegas-viz%2FVegas/lists"}