digital-cognition-co-in / DigitalCognition

DigitalCognition - Main repo - Core Product
3 stars 2 forks source link

Deep dive Visualizations with - Bokeh , Holoviews , PlotlyJS , d3.js , dc.js and maybe Seaborn #42

Open RohitDhankar opened 4 years ago

RohitDhankar commented 4 years ago

Deep dive Visualizations with - Bokeh , Holoviews , PlotlyJS , d3.js , dc.js and maybe Seaborn @RohitDhankar and @RohanMathur17 to collab .

Existing old code here - https://github.com/digital-cognition-co-in/DigitalCognition/blob/97d80d279d8cf0cb5f85a2264bab8e2f23e7a44c/dc_dash/dc_bokeh_plots.py#L19

@S-T-A-R-L-O-R-D ( DEVESH SOLANKI ) to collab with @RohanMathur17 for Plotly Python version and Bokeh plots / charts.

S-T-A-R-L-O-R-D commented 4 years ago

Screenshot (72) It's an Interactive Plot, if we hover over any field it will display more information about that field like tableau Looking forward to creating more engaging and Interactive visuals.

RohitDhankar commented 4 years ago

@S-T-A-R-L-O-R-D - thanks Devesh , this is awesome :)

S-T-A-R-L-O-R-D commented 4 years ago

from bokeh.plotting import figure, output_file, show, ColumnDataSource from bokeh.models.tools import HoverTool from bokeh.transform import factor_cmap from bokeh.palettes import Blues8 from bokeh.embed import components from bokeh.io import output_notebook,show import pandas as pd

x = [1, 2, 3, 4, 5]

y = [4, 6, 2, 4, 3]

Read CSV

df = pd.read_csv("cars.csv")

car = df['Car']

hp = df['Horsepower']

ColumnDataSource from data frame

source = ColumnDataSource(df)

output_notebook() output_file("index.html")

Add plot

p = figure( y_range=source.data['Car'].tolist(), plot_width=800, plot_height=600, title="Cars With Top Horsepower ", x_axis_label="Horsepower", tools="pan,box_select,zoom_in,zoom_out,save,reset")

Render Glyph

p.hbar(y='Car', right='Horsepower', left=0, height=0.4, fill_color=factor_cmap('Car',palette=Blues8,factors=source.data['Car'].tolist()), fill_alpha=0.5, legend='Car' ,source=source)

Adding Legend

p.legend.orientation='vertical' p.legend.location='top_right' p.legend.label_text_font_size='10px'

Adding Tooltip

hover = HoverTool() hover.tooltips = """

@Car

Price: @Price
Horsepower: @Horsepower
Cars

""" p.add_tools(hover)

show results

show(p)

print out div and script

script,div=components(p) print(div) print(script)