Introduction to Charting

There are a host of valuable tools that can be created for ArcGIS users that include charts of data. The "MatPlotLib" package provides a large variety of charts for Python scripts and allows customization of the charts to suit a broad range of needs. MatPlotLib requires that statistical package, NumPy.

1. Installing NumPy and MatPlotLib

Before using MatPlotLib we need to install it and install NumPy. Installation instructions for MatPlotLib and links to the NumPy installer are available at An installer is available for MatPlotLib at MatPlotLib Installation Instructions. When you investigate new packages you may see information on "compliing" the package. This is for developers familiar with complied languages, you'll want to avoid these instructions for now and go with the "pre-compiled binaries" or an "exe" installer.

When you run the code below, you may also end up with errors that additional packages need to installed (including dateutil, six, and others). For each one, I recommend referencing the "Unofficial Windows Binaries for Python Extension Packages". These installers are very easy to use and very fast.

2. Creating Simple Bar Charts

The code sample below will put up a simple bar chart in a window using MatPlotLib.

import numpy
import matplotlib.pyplot as pyplot

Counts=[20, 35, 30, 35, 27] # this is the histogram data
XPositions=range(5) # defines the positions of the bars in the histogram
BarWidth=0.35 # defines the width of each bar in the histogram,Counts,BarWidth) # add the bar to the plot
pyplot.ylabel('Count') # add a label to the vertical axis
pyplot.title('Histogram') # add a title to the top of the chart # shows the hisogram in a window

MatPlotLib is fairly complex but there are a wealth of examples and information on how to use it on the MatPlotLib website.

Note that the code above does not use tkinter to display message boxes. We have not been able to figure out how to get tkinter to quit if we put up a matplotlib chart. You can use tkinter if you do not "withdraw" the "root" and then close the mode-less windows that appears.

3. 3D Charts

I aways have questions on 3D charts to display geospatial data. There are a number of 3D plotting libraries for Python and I have had luck with Matplotlib's mplot3d. Try this tutorial first:

Matplotlib: mplot3d

and then check out these examples:

2D plots in 3D

Additional Resources

MatPlotLib website


© Copyright 2018 HSU - All rights reserved.