Skip to content

Instantly share code, notes, and snippets.

@podhmo
Last active April 13, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/d6eed9e154d848c4f276724adc6a5524 to your computer and use it in GitHub Desktop.
Save podhmo/d6eed9e154d848c4f276724adc6a5524 to your computer and use it in GitHub Desktop.
# import vega_datasets # error on import panda
import importlib.util
import pathlib
datasets = {}
spec = importlib.util.find_spec("vega_datasets")
for location in spec.submodule_search_locations:
p = pathlib.Path(location)
if (p / "_data").exists():
for f in (p / "_data").glob("*.json"):
datasets[f.name] = f
print(list(datasets.keys()))
import pygal
import pathlib
import json
from collections import defaultdict
import importlib.util
# dataset
spec = importlib.util.find_spec("vega_datasets")
dirpath = spec.submodule_search_locations[0]
with (pathlib.Path(dirpath) / "_data/iris.json").open() as rf:
data = json.load(rf)
# aggregate
d = defaultdict(list)
for row in data:
d[row["species"]].append(row)
# render graph
xy_chart = pygal.XY(stroke=False)
xy_chart.title = "Correlation"
for species, rows in d.items():
xy_chart.add(species, [(row["sepalWidth"], row["sepalLength"]) for row in rows])
print(xy_chart.render(is_unicode=True))
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
SHELL := $(shell which bash)
00:
python $(shell echo $@*.py)
01:
python $(shell echo $@*.py) |& tee $(patsubst %.py,%.svg,$(shell echo $@*.py))
setup:
python -m pip install --no-deps vega_datasets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment