How to do it...

  1. Import matplotlib:
>>> import matplotlib.pyplot as plt
  1. Prepare the data to be displayed on the graph and split it into different arrays:
>>> DATA = (
... ('Q1 2017', 100),
... ('Q2 2017', 150),
... ('Q3 2017', 125),
... ('Q4 2017', 175),
... )
>>> POS = list(range(len(DATA)))
>>> VALUES = [value for label, value in DATA]
>>> LABELS = [label for label, value in DATA]
  1. Create a bar graph with the data:
>>> plt.bar(POS, VALUES)
>>> plt.xticks(POS, LABELS)
>>> plt.ylabel('Sales')
  1. Save the graph to the hard drive:
>>> plt.savefig('data.png')
    ..................Content has been hidden....................

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