Plotly


Plotly is a library that allows you to create interactive plots that you can use in dashboards or websites.

https://plotly.com/python/plotly-express/

Setup

> import plotly.express as px
+ import numpy as np
+ import pandas as pd

Scatter

> df3 = px.data.iris()
+ fig = px.scatter(df3, x="sepal_width", 
+   y="sepal_length", color="species");
+ fig.write_html("scatter1.html")
> htmltools::includeHTML('scatter1.html')
> df4 = px.data.iris()
+ fig = px.scatter(df4, x="sepal_width", y="sepal_length",
+ color="species", marginal_y="violin",
+ marginal_x="box", trendline="ols", 
+ template="simple_white")
+ 
+ fig.write_html("scatter2.html")
> htmltools::includeHTML('scatter2.html')
> fig = px.scatter_matrix(df4, dimensions=["sepal_width", 
+ "sepal_length", "petal_width", "petal_length"], 
+ color="species")
+ 
+ fig.write_html("scatter3.html")
> htmltools::includeHTML('scatter3.html')

Bar Plots

> df5 = px.data.tips()
+ fig = px.bar(df5, x="sex", y="total_bill", 
+   color="smoker", barmode="group")
+ fig.write_html("bar1.html")
> htmltools::includeHTML('bar1.html')
> fig = px.bar(df5, x="sex", y="total_bill", color="smoker", 
+ barmode="group", facet_row="time", facet_col="day", 
+ category_orders={"day": ["Thur", "Fri", "Sat", "Sun"],
+ "time": ["Lunch", "Dinner"]})
+ 
+ fig.write_html("bar2.html")
> htmltools::includeHTML('bar2.html')

Boxplots

> fig = px.box(df5, x="day", y="total_bill", 
+   color="smoker", notched=True)
+ fig.write_html("box.html")
> htmltools::includeHTML('box.html')

Histogram

> fig = px.histogram(df5,x="total_bill", color="sex")
+ fig.write_html("hist1.html")
> htmltools::includeHTML('hist1.html')

Violin

> fig = px.violin(df5, y="tip", x="smoker", 
+ color="sex", box=True, points="all", 
+ hover_data=df5.columns)
+ fig.write_html("violin.html")
> htmltools::includeHTML('violin.html')

Density Contour

> fig = px.density_contour(df4, x="sepal_width", 
+ y="sepal_length", color="species", 
+ marginal_x="rug", marginal_y="histogram")
+ fig.write_html("contour.html")
> htmltools::includeHTML('contour.html')