CHAPTER 9 - PYTHON PLOTTING



AD

9.1 A simple Python plot

We must import the matplotlib package using PyCharm package manager. The process is described in the section 9.2 . Pyplot plots the graph, and numpy holds the variables.

#import matplotlib to plot graphs
import matplotlib.pyplot as plt
import numpy as np
days = [1,3,5,6,8,]
temp = [37,34,37,35,34]
plt.plot(days, temp)
plt.show()

The plot can be seen below. You can make the plot much fancier depending on your needs. There are many examples on the internet.

Sample Python Matplotlib graph.


9.2 Installing the Python matplotlib package

Press Ctrl → Alt → s in the PyCharm window. The Settings window will open. Under Project select Python Interpreter.

Pycharm Settings screen.


Click the plus sign (+) on the right. A new window will appear with the available packages. Type matplotlib next to the search icon. Be sure matplotlib is highlighted, and click Install Package.

Pycharm Available Packages screen.


You will see the following screen saying Package ‘matplotlib’ installed successfully. You can close the open windows, the package is installed.

Pycharm Package matplotlib installed successfully screen.

9.3 Problems installing matplotlib package

There are many reasons why a package doesn't install correctly. The simplest thing to try is uninstalling the matplotlib package, and reinstalling the package with a lower version number.

theSurfDragon.com


Win-Python Navigation

Table of Contents
Ch1-Starting Out
Ch2-Loops
Ch3-If Statements
Ch4-Functions
Ch5-Variable Scope
Ch6-Bubble Sort
Ch7-Intro to OOP
Ch8-Inheritance
Ch9-Plotting
Ch10-Files
Ch11-Print Format
Ch12-Dict-Zip-Comp
Ch13-Slice Arrays