Wednesday, November 25, 2015

Plotting Charts with PyQGIS

In this post, I will show an example of how to plot a simple line graph in PyQGIS, with matplotlib library. This library is already included in PyQGIS.

The example code is below.

import matplotlib.pyplot as plt



# x and y data as same length lists

radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]

area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]



plt.plot(radius, area)

plt.xlabel('Radius')

plt.ylabel('Area')

plt.title('Area of a Circle')

# show grid lines

ax = plt.axes()

ax.grid(True)

# show plot window

plt.show()

No comments:

Post a Comment