Last active
April 13, 2020 22:44
-
-
Save podhmo/d6eed9e154d848c4f276724adc6a5524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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