How to do it...

  1. Import matplotlib:
>>> import matplotlib.pyplot as plt
  1. Prepare the data. This represents two products' sales:
>>> DATA = (
... ('Q1 2017', 100, 5),
... ('Q2 2017', 105, 15),
... ('Q3 2017', 125, 40),
... ('Q4 2017', 115, 80),
... )
  1. Process the data to prepare the expected format:
>>> POS = list(range(len(DATA)))
>>> VALUESA = [valueA for label, valueA, valueB in DATA]
>>> VALUESB = [valueB for label, valueA, valueB in DATA]
>>> LABELS = [label for label, value1, value2 in DATA]
  1. Create the line plot. Two lines are required:
>>> plt.plot(POS, VALUESA, 'o-')
>>> plt.plot(POS, VALUESB, 'o-')
>>> plt.ylabel('Sales')
>>> plt.xticks(POS, LABELS)
  1. Display the graph:
>>> plt.show()
  1. The result will be displayed in a new window:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.49.160