Introduction: Python - Create Plot Line Chart Using Matplotlib

About: Occupation: tech support

In order to use the Matplotlib library, it must be installed first:

  1. Open a command line (in Linux, I used Xfce Terminal)
  2. Install "pip", the Python package manager (this was for Python3):

    python3 -m pip install -U pip

  3. Install Matplotlib:

    python3 -m pip install -U matplotlib

The Python program below and attached will generate a simple line plot graph:

import matplotlib.pyplot as mattexample

print ("Imported matplotlib")

print ("Setting up the x axis values.")
# x axis values
x = [2, 4, 6, 8, 10, 12, 14, 16]

print ("Setting up the y axis values.")
# y axis
y = [7, 5, 8, 6, 7, 8, 10, 14]

print("The x axis values are: ",x)
print("The y axis values are: ", y)

# Invoke plot function to create the graph
print ("Now invoking the plot function.")
mattexample.plot(x,y)

# Invoke the show function to display the plot graph
print ("Now showing the plot graph that was generated.")
mattexample.show()