import pandas as pd import holoviews as hv from holoviews import opts, dim hv.extension('bokeh', 'matplotlib') diamonds = pd.read_csv('../data/diamonds.csv') diamonds.head() hv.Scatter(diamonds.sample(5000), 'carat', 'price') scatter = hv.Scatter(diamonds.sample(5000), 'carat', ['price', 'cut']).redim.label(carat='Carat (ct)', price='Price ($)') scatter.opts(width=600, logy=True, tools=['hover']) scatter.opts(opts.Scatter(width=600, logy=True, tools=['hover'])) # Exercise: Try inspecting some of the tab-completable keywords for Curve elements # Note: You can see the available completions by pressing Tab inside opts. # Exercise: Try enabling the boolean show_grid plot option for the curve above # hv.help(hv.Scatter) scatter.opts(color=dim('cut'), alpha=0.5, cmap='Set1') # Exercise: Display scatter without any new options to verify it stays colored # Exercise: Try setting the 'size' style options to 1 # Exercise: Try using an options builder and exploring some of the completions hv.output(scatter, backend='matplotlib') hv.output(backend='matplotlib') selection = scatter.select(carat=(0, 3)) selection.opts(aspect=4, fig_size=400, color='blue', s=4, alpha=0.2) # Exercise: Apply the color and alpha options as above, but to the matplotlib plot hv.output(fig='svg') scatter.opts(aspect=4, fig_size=400, xrotation=70, color='green', s=10, marker='^') # Exercise: Verify for yourself that the output above is SVG and not PNG # You can do this by right-clicking above then selecting 'Open Image in a new Tab' (Chrome) or 'View Image' (Firefox) hv.output(backend='bokeh') #%%output fig='png' filename='diamonds' hv.save(scatter, fmt='png', filename='diamonds') scatter ls *.png low_clarity = diamonds[diamonds.clarity=='I1'] high_clarity = diamonds[diamonds.clarity=='IF'] opts.defaults( opts.Spikes(width=900, logx=True, xticks=8, xrotation=90)) overlay = (hv.Spikes( low_clarity, 'price', 'carat', group='Diamonds', label='Low') * hv.Scatter( low_clarity, 'price', 'carat', group='Diamonds', label='Low') * hv.Spikes( high_clarity, 'price', 'carat', group='Diamonds', label='High') * hv.Scatter(high_clarity, 'price', 'carat', group='Diamonds', label='High')) overlay.opts( opts.Spikes('Diamonds.Low', color='blue'), opts.Spikes('Diamonds.High', color='red')) # Exercise: Remove the call to the .opts method above and observe the effect # Exercise: Give the 'Low' clarity scatter points a black 'line_color' # Optional Exercise: Try differentiating the two sets of spikes by group and not label