Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions pyalgotrade/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

import collections

import numpy as np
import broker

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -74,12 +74,21 @@ def getMarker(self):
def needColor(self):
raise NotImplementedError()

def plot(self, mplSubplot, dateTimes, color):
def plot(self, mplSubplot, dateTimes, color, valid_only=True):
values = []
for dateTime in dateTimes:
values.append(self.getValue(dateTime))
mplSubplot.plot(dateTimes, values, color=color, marker=self.getMarker())

if(valid_only):
# we'll write a custom formatter
N = len(dateTimes)
ind = np.arange(N) # the evenly spaced plot indices
mplSubplot.plot(ind, values, color=color, marker=self.getMarker())
def format_date(x):
thisind = np.clip(int(x+0.5), 0, len(dateTimes)-1)
return dateTimes[thisind].strftime('%Y-%m-%d %H:%M:%S')
mplSubplot.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
else:
mplSubplot.plot(dateTimes, values, color=color, marker=self.getMarker())

class BuyMarker(Series):
def getColor(self):
Expand Down Expand Up @@ -172,7 +181,7 @@ def needColor(self):
def getColorForValue(self, value, default):
return default

def plot(self, mplSubplot, dateTimes, color):
def plot(self, mplSubplot, dateTimes, color, valid_onl=True):
validDateTimes = []
values = []
colors = []
Expand Down