Skip to content
This repository
tree: 47a3621a1d
Fetching contributors…

Cannot retrieve contributors at this time

file 116 lines (93 sloc) 3.066 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
import pylab
from matplotlib import pyplot
from PlotInfo import PlotInfo
from StepType import StepType
import warnings
from Marker import Marker
from LineStyle import LineStyle

class Line(PlotInfo):
    steps = StepType("steps")

    def __init__(self,
                 color='black',
                 width=1,
                 lineStyle='-',
                 marker=None,
                 markerSize=8.0,
                 dates=False,
                 loglog=False,
                 steps=None,
                 alpha=None,
                 antialiased=False,
                 **kwargs
                ):
        super(Line,self).__init__("line", **kwargs)

        self._marker = Marker()
        self._marker.marker = marker
        self._marker.size = markerSize

        # TODO Change to width
        self.lineWidth = width
        self.color = color
        self._lineStyle = LineStyle()
        self._lineStyle.style = lineStyle
        self.dates = dates
        self.loglog = loglog
        self.steps = steps

        self.alpha = alpha
        self.antialiased = antialiased

    @property
    def lineStyle(self):
        return self._lineStyle.style

    @lineStyle.setter
    def lineStyle(self, value):
        self._lineStyle.style = value

    @property
    def marker(self):
        return self._marker.marker

    @marker.setter
    def marker(self, value):
        self._marker.marker = value

    @marker.getter
    def marker(self):
        return self._marker.marker

    @property
    def markerSize(self):
        return self._marker.size

    @markerSize.setter
    def markerSize(self, value):
        self._marker.size = value

    @markerSize.getter
    def markerSize(self):
        return self._marker.size

    def stepFunction(self, stepType="pre"):
        self.steps = stepType

    def draw(self, fig, axis):
        super(Line, self).draw(fig, axis)

        if self.dates:
            plotFunc = axis.plot_date
        elif self.loglog:
            warnings.warn("Setting loglog in Lines will be deprecated soon. "
                          "Set this in Plot instead.",
                          warnings.PendingDeprecationWarning)
            plotFunc = axis.loglog
        else:
            plotFunc = axis.plot

        kwdict = self.getAttributes()
        kwdict["linestyle"] = self.lineStyle
        kwdict["color"] = self.color
        kwdict["label"] = self.label
        kwdict["linewidth"] = self.lineWidth

        if self.steps is not None:
            kwdict["drawstyle"] = "steps-%s" % (self.steps)

        if self.marker is not None:
            kwdict["marker"] = self.marker
            kwdict["markersize"] = self.markerSize
        else:
            kwdict["marker"] = "None"

        if self.antialiased:
            kwdict["antialiased"] = self.antialiased
        if self.alpha is not None:
            kwdict["alpha"] = self.alpha

        handle = plotFunc(self.xValues, self.yValues, **kwdict)

        if type(handle) == list:
            handle = handle[0]

        return [[handle], [self.label]]
Something went wrong with that request. Please try again.