for yr in gapminder_ds.keys() }) # Define options # Combine Points and Text hvgapminder = (gapminder_ds * text).opts( opts.Points(alpha=0.6, color='Group', cmap='Set1', line_color='black', size=np.sqrt(dim('Population')) * 0.005, tools=['hover'], title='Gapminder Demo', responsive=True, show_grid=True), opts.Text(text_font_size='52pt', text_color='lightgray')) # Define custom widgets def animate_update(): year = slider.value + 1 if year > end: year = int(start) slider.value = year # Update the holoviews plot by calling update with the new year. def slider_update(event): hvplot.update((event.new, ))
# width=500, height=400) ds = xr.DataArray(zi, dims=['Lat', 'Lon'], coords={'Lat': lats, 'Lon': lons}).to_dataset(name='PM2_5') aqi_ds = gv.Dataset(ds, ['Lon', 'Lat'], 'PM2_5') background = gvts.EsriImagery * gv.Image(aqi_ds).opts(alpha=0.7, width=500, height=400, colorbar=True, cmap='magma',clim=(0,70), color_levels = levels) contour = gvts.EsriReference * aqi_ds.to(gv.FilledContours, #gvts.CartoEco is the original ['Lon', 'Lat']).opts(alpha=0.5, width=500, height=400, colorbar=True, cmap='magma', levels=10, color_levels=10, tools=['hover']) text_opts = opts.Text(text_align='center', text_baseline='middle', text_font='Arial',width = 500, height = 400) test3 = (test + background + contour + hv.Text(0.5, 0.5, begin.strftime("%m/%d/%Y %H:%M")).opts(text_opts)).cols(2) print(type(test)) print(type(background)) print(type(contour)) print(type(test3)) #renderer = hv.Store.renderers['matplotlib'].instance(fig='svg', holomap='gif') #renderer.save(test3, 'test3') #renderer = hv.plotting.mpl.MPLRenderer.instance(dpi=120) #layout_test3 = renderer.get_plot(test3) #print(type(layout_test3)) #print(type(test3))
import pandas as pd import numpy as np import holoviews as hv from holoviews import opts, dim hv.extension('bokeh') macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t') key_dimensions = [('year', 'Year'), ('country', 'Country')] value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'), ('gdp', 'GDP Growth'), ('trade', 'Trade')] macro = hv.Table(macro_df, key_dimensions, value_dimensions) gdp_curves = macro.to.curve('Year', 'GDP Growth') gdp_unem_scatter = macro.to.scatter('Year', ['GDP Growth', 'Unemployment']) annotations = hv.Arrow(1973, 8, 'Oil Crisis', 'v') * hv.Arrow(1975, 6, 'Stagflation', 'v') *\ hv.Arrow(1979, 8, 'Energy Crisis', 'v') * hv.Arrow(1981.9, 5, 'Early Eighties\n Recession', 'v') composition=(gdp_curves * gdp_unem_scatter* annotations) composition.opts( opts.Curve(color='k'), opts.Scatter(cmap='Blues', color='Unemployment', line_color='k', size=dim('Unemployment')*1.5), opts.Text(text_font_size='13px'), opts.Overlay(height=400, show_frame=False, width=700)) hv.save(composition, 'holomap.html')
default_fontsizes = dict(title=8, labels=8, ticks=7, minor_ticks=7, legend=7) fig_opts = [ opts.Layout(aspect_weight=1, fig_inches=(3.42, None), sublabel_size=10, fontsize=8), opts.Overlay(fontsize=default_fontsizes, ), opts.Area(fontsize=default_fontsizes), opts.Arrow(textsize=default_fontsizes), opts.Curve(fontsize=default_fontsizes), opts.HexTiles(fontsize=default_fontsizes), opts.Histogram(fontsize=default_fontsizes), opts.Raster(fontsize=default_fontsizes), opts.Scatter(fontsize=default_fontsizes), opts.Text(fontsize=default_fontsizes), opts.QuadMesh(fontsize=default_fontsizes), opts.Violin(fontsize=default_fontsizes), opts.VLine(fontsize=default_fontsizes), ] # hv hooks class Suptitle: def __init__(self, suptitle, color, y=1.175): self.suptitle = suptitle self.color = color self.y = y def __call__(self, plot, element):