Showing posts with label PLotting Charts. Show all posts
Showing posts with label PLotting Charts. Show all posts

Wednesday, June 7, 2017

Python and Pandas - How to plot Multiple Curves with 5 Lines of Code

In this post I will show how to use pandas to do a minimalist but pretty line chart, with as many curves we want.

In this case I will use a I-D-F precipitation table, with lines corresponding to Return Periods (years) and columns corresponding to durations, in minutes. as shown below:


For the code to work properly, the table must have headers in the columns and lines, and the first cell have to be blank. Select the table you want in your SpreadSheet Editor, and copy it to clipboard.

Then, run the following code:


import pandas as pd

table = pd.read_clipboard()
tabTr = table.transpose().convert_objects(convert_numeric=True)
eixox = tabTr.index.values.astype(float)
tabTr.set_index(eixox).plot(grid=True)

And Voila!:


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()