def test_bqplot_topo_load(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_bqplot_topo_load") f = 'WorldMap.json' full = os.path.join(temp, f) url = "https://raw.githubusercontent.com/bloomberg/bqplot/master/bqplot/map_data/" get_url_content_timeout(url + f, output=full) r = topo_load(full) assert r if not isinstance(r, dict): raise TypeError(type(r))
def test_bqplot_topo_load(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_bqplot_topo_load") f = 'WorldMap.json' full = os.path.join(temp, f) url = "https://raw.githubusercontent.com/bloomberg/bqplot/master/bqplot/map_data/" get_url_content_timeout(url + f, output=full) r = topo_load(full) assert r if not isinstance(r, dict): raise TypeError(type(r))
def create_map(self, map_file): first_year = self.years[0] first_provincial_income_proportion = self.get_provincial_income_proportion( first_year) sc_geo = Mercator(scale_factor=7000, center=(5.5, 53.0)) tooltip = Tooltip(fields=["name"], labels=["province"]) return Map( map_data=topo_load(map_file), scales={ "projection": sc_geo, "color": self.col_scale }, colors={"default_color": "Grey"}, color=first_provincial_income_proportion, tooltip=tooltip, interactions={ "click": "select", "hover": "tooltip" }, visible=True, )
import pandas as pd import bqplot import us names = [ "date", "city", "state", "country", "shape", "duration_seconds", "duration_reported", "description", "report_date", "latitude", "longitude" ] fn = "/srv/nbgrader/data/ufo-scrubbed-geocoded-time-standardized.csv", ufo = pd.read_csv(fn, names=names, parse_dates=["date", "report_date"]) abbr_to_fits = us.states.mapping('abbr', 'fips') ufo["fips"] = ufo["state"].apply( lambda a: int(abbr_to_fits.get(str(a).upper(), -1))) map_styles = { 'scales': { 'projection': bqplot.AlbersUSA(), 'color': bqplot.ColorScale(colors=["red", "blue"]) }, 'color': fips_count.to_dict() } states_map = bqplot.Map(map_data=bqplot.topo_load('map_data/USStatesMap.json'), **map_styles) map_fig = bqplot.Figure(marks=[states_map], title='USA')
"""# Get import""" from kmdvalg import kommune from bqplot import pyplot as plt from bqplot import (Map, Mercator, Orthographic, ColorScale, ColorAxis, AlbersUSA, topo_load, Tooltip) import os """# Example 1""" sc_geo = Mercator() map_mark = Map(scales={'projection': sc_geo}) fig = plt.figure(marks=[map_mark], title='Basic Map Example') if kommune.check_isnotebook(): display(fig) """# Example 2""" #sc_geo = Mercator() sc_geo = Orthographic(scale_factor=375, center=[0, 25], rotate=(-50, 0)) map_mark = Map(map_data=topo_load('map_data/WorldMap.json'), scales={'projection': sc_geo}, colors={ 682: 'Green', 356: 'Red', 643: '#0000ff', 'default_color': 'DarkOrange' }) fig = plt.figure(marks=[map_mark], fig_color='deepskyblue', title='Advanced Map Example') if kommune.check_isnotebook(): display(fig) """# Example 3""" sc_geo = Mercator() sc_c1 = ColorScale(scheme='YlOrRd')