plot.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. '''
  2. Created on May 15, 2017
  3. @author: Bart
  4. '''
  5. from serializable import Serializable
  6. class Plot(Serializable):
  7. def __init__(self, datasets, title=None, x=None, y=None, legend=None):
  8. self.title = title
  9. if x == None:
  10. x = Axis()
  11. self.x = x
  12. if y == None:
  13. y = Axis()
  14. self.y = y
  15. if legend == None:
  16. # we set legend to true in case of a multiplot where all legend entries are defined
  17. legend = len(datasets) > 1 and all(map(lambda d : d.legend, datasets))
  18. self.legend = legend
  19. self.datasets = datasets
  20. class DataSet(Serializable):
  21. def __init__(self, datapoints, color=None, linestyle=None, legend=None):
  22. self.color = color
  23. self.linestyle = linestyle
  24. self.datapoints = datapoints
  25. self.legend = legend
  26. class DataPoint(Serializable):
  27. def __init__(self, x, y):
  28. self.x = x
  29. self.y = y
  30. class Color:
  31. # enumeration of all colors
  32. BLUE, GREEN, RED, CYAN, MAGENTA, YELLOW, BLACK, WHITE = ("blue", "green", "red", "cyan", "magenta", "yellow", "black", "white")
  33. class LineStyle:
  34. # enumeration of all line styles
  35. SOLID, DASHED, DASHDOT, DOTTED, PIXEL, POINT, CIRCLE, STAR, PLUS, X = ("solid", "dashed", "dashdot", "dotted", "pixel", "point", "circle", "star", "plus", "x")
  36. class Axis(Serializable):
  37. def __init__(self, name=None, unit=None, lim_low=None, lim_high=None):
  38. if not name:
  39. name = ""
  40. self.name = name
  41. if not unit:
  42. unit = ""
  43. self.unit = unit
  44. self.lim_low = lim_low
  45. self.lim_high = lim_high
  46. class XAxis(Axis): pass
  47. class YAxis(Axis): pass