convert plot_profit to use Plotly instead of matplotlib
This commit is contained in:
parent
ffb60fe8b9
commit
9b8cb05037
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import matplotlib.dates as mdates
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
import plotly
|
||||||
|
from plotly import tools
|
||||||
|
from plotly.offline import plot
|
||||||
|
import plotly.graph_objs as go
|
||||||
|
|
||||||
import freqtrade.optimize as optimize
|
import freqtrade.optimize as optimize
|
||||||
import freqtrade.misc as misc
|
import freqtrade.misc as misc
|
||||||
import freqtrade.exchange as exchange
|
import freqtrade.exchange as exchange
|
||||||
@ -122,30 +125,32 @@ def plot_profit(args) -> None:
|
|||||||
# Plot the pairs average close prices, and total profit growth
|
# Plot the pairs average close prices, and total profit growth
|
||||||
#
|
#
|
||||||
|
|
||||||
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
|
avgclose = go.Scattergl(
|
||||||
fig.suptitle('total profit')
|
x=dates,
|
||||||
|
y=avgclose,
|
||||||
|
name='Avg close price',
|
||||||
|
)
|
||||||
|
profit = go.Scattergl(
|
||||||
|
x=dates,
|
||||||
|
y=pg,
|
||||||
|
name='Profit',
|
||||||
|
)
|
||||||
|
|
||||||
ax1.plot(dates, avgclose, label='avgclose')
|
fig = tools.make_subplots(rows=3, cols=1, shared_xaxes=True, row_width=[1, 1, 1])
|
||||||
ax2.plot(dates, pg, label='profit')
|
|
||||||
ax1.legend(loc='upper left')
|
fig.append_trace(avgclose, 1, 1)
|
||||||
ax2.legend(loc='upper left')
|
fig.append_trace(profit, 2, 1)
|
||||||
|
|
||||||
# FIX if we have one line pair in paris
|
|
||||||
# then skip the plotting of the third graph,
|
|
||||||
# or change what we plot
|
|
||||||
# In third graph, we plot each profit separately
|
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
pg = make_profit_array(data, max_x, pair)
|
pg = make_profit_array(data, max_x, pair)
|
||||||
ax3.plot(dates, pg, label=pair)
|
pair_profit = go.Scattergl(
|
||||||
ax3.legend(loc='upper left')
|
x=dates,
|
||||||
# black background to easier see multiple colors
|
y=pg,
|
||||||
ax3.set_facecolor('black')
|
name=pair,
|
||||||
xfmt = mdates.DateFormatter('%d-%m-%y %H:%M') # Dont let matplotlib autoformat date
|
)
|
||||||
ax3.xaxis.set_major_formatter(xfmt)
|
fig.append_trace(pair_profit, 3, 1)
|
||||||
|
|
||||||
fig.subplots_adjust(hspace=0)
|
plot(fig, filename='freqtrade-profit-plot.html')
|
||||||
fig.autofmt_xdate() # Rotate the dates
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user