To continue with the example of creating Candlestick Charts using Python with Pandas and Plotly, I want to show how easy it is to export these into HTML files.
This technique is super useful as you can send clients results in minutes. As long as they have a browser to view the file then there will be no need to show them how to setup a Python environment. This rarely workouts that well…
Required Imports
The only additional import we need, if we are using the previous tutorial, is from the Plotly Offline library.
from plotly.offline import plot
The Plot Function
All that’s left to do is to call the plot()
function and pass in our parameters.
plot(fig, filename = "BAND Candlestick Export.html", auto_open = False)
The fig
is our chart information. The filename
is the name given to our HTML file. I personally like setting the auto_open
to false as it will open a new tab automatically and take your away from your Python environment.
Full Code Example
For this full code example I’ve also included our chart example from Candlestick Charts using Python with Pandas and Plotly.
from plotly.offline import plot
import plotly.graph_objects as go
import pandas as pd
ltc = pd.read_csv('LTC Day History.csv')
fig = go.Figure(
data = [go.Candlestick(
x = ltc['Start Time'],
open = ltc['Price Open'],
high = ltc['Price High'],
low = ltc['Price Low'],
close = ltc['Price Close']
)]
)
fig.show()
plot(fig, filename = "LTC Candlestick Export.html", auto_open = False)