def test_data_by_url():
    for name in list_datasets():
        url = load_dataset(name, url_only=True)
        assert url.startswith('https://')

    bad_dataset = 'blahblahblah'
    with pytest.raises(ValueError) as excinfo:
        load_dataset(bad_dataset)
    assert 'No such dataset {0}'.format(bad_dataset) in str(excinfo.value)
Exemplo n.º 2
0
def test_data_by_url():
    for name in list_datasets():
        url = load_dataset(name, url_only=True)
        assert url.startswith('https://')

    bad_dataset = 'blahblahblah'
    with pytest.raises(ValueError) as excinfo:
        load_dataset(bad_dataset)
    assert 'No such dataset {0}'.format(bad_dataset) in str(excinfo.value)
Exemplo n.º 3
0
    def getAltair(self, params):
        cars = load_dataset('cars')

        c = Chart(cars).mark_point().encode(x='Horsepower',
                                            y='Miles_per_Gallon',
                                            color='Origin')

        return c.to_html()
Exemplo n.º 4
0
    def getAltair(self, params):
        cars = load_dataset('cars')

        c = Chart(cars).mark_point().encode(
            x='Horsepower',
            y='Miles_per_Gallon',
            color='Origin'
        )

        return c.to_html()
Exemplo n.º 5
0
def return_vega_json(dataset_name):

    cars = alt.load_dataset(dataset_name)

    j = alt.Chart(cars).mark_point().encode(
        x='Horsepower',
        y='Miles_per_Gallon',
        color='Origin',
    ).to_json()

    return jsonify(j)
Exemplo n.º 6
0
# coding=utf-8
from dataviz import Dataviz
from altair import Chart, load_dataset, X, Y

df = load_dataset('seattle-weather')

dataviz = Dataviz("Seattle Weather")

overview_chart = Chart(df).mark_bar(stacked='normalize').encode(
    X('date:T', timeUnit='month'),
    Y('count(*):Q'),
    color='weather',
)

dataviz.add("commented", title="Overview", charts=[overview_chart],
            comment= "Lorem ipsum dolor sit amet, cum pertinacia definitionem an. His ne oratio facilis voluptatum, nam lorem putant qualisque ad. Mea in affert nostrum. Mea cu ignota adipiscing. Omnis mnesarchum vix cu, omnes impedit democritum nec te. Malorum urbanitas consectetuer ei eam, no sea paulo tollit detracto."
            )

chart_a = Chart(df).mark_bar().encode(
    X('precipitation', bin=True),
    Y('count(*):Q')
)

chart_b = Chart(df).mark_line().encode(
    X('date:T', timeUnit='month'),
    Y('average(precipitation)')
)

chart_c = Chart(df).mark_line().encode(
    X('date:T', timeUnit='month'),
    Y('average(temp_max)'),
Exemplo n.º 7
0
"""
Trellis Histogram
-----------------
This example shows how to make a basic trellis histogram.
https://vega.github.io/vega-lite/examples/trellis_bar_histogram.html
"""
import altair as alt

cars = alt.load_dataset('cars')

chart = alt.Chart(cars).mark_bar().encode(alt.X("Horsepower",
                                                type="quantitative",
                                                bin=alt.Bin(maxbins=15)),
                                          y='count(*):Q',
                                          row='Origin')
Exemplo n.º 8
0
"""
Histogram
-----------------
This example shows how to make a basic histogram, based on the vega-lite docs
https://vega.github.io/vega-lite/examples/histogram.html
"""
import altair as alt

movies = alt.load_dataset('movies')

chart = alt.Chart(movies).mark_bar().encode(
    x=alt.X("IMDB_Rating",
            type='quantitative',
            bin=alt.BinTransform(maxbins=10, )),
    y='count(*):Q',
)
Exemplo n.º 9
0
"""
Box Plot with Min/Max Whiskers
-----------------
This example shows how to make a basic box plot using US Population
data from 2000.

https://vega.github.io/vega-lite/examples/box-plot_minmax_2D_vertical_normalized.html
"""
import altair as alt

population = alt.load_dataset('population')

# Define aggregate fields
lower_box = 'q1(people)'
lower_whisker = 'min(people)'
upper_box = 'q3(people)'
upper_whisker = 'max(people)'

# Compose each layer individually
lower_plot = alt.Chart(population).mark_rule().encode(y=alt.Y(
    lower_whisker, axis=alt.Axis(title="population")),
                                                      y2=lower_box,
                                                      x='age:O')

middle_plot = alt.Chart(population).mark_bar(size=5.0).encode(y=lower_box,
                                                              y2=upper_box,
                                                              x='age:O')

upper_plot = alt.Chart(population).mark_rule().encode(y=upper_whisker,
                                                      y2=upper_box,
                                                      x='age:O')
Exemplo n.º 10
0
from altair import Chart, load_dataset

# load data as a pandas DataFrame
cars = load_dataset('cars')

Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)