Recent Posts

Plot 2 different variables using 2 y-axis (from Satlantic’s LOBO server)

Here we will make a plot using 2 different dependent variables with different scales. Satlantic LOBO is a ocean observatory moored in the North West Arm (Halifax, Nova Scotia, Canada). In this post, we’ll query the LOBO server to create a temperature and salinity plot.




import urllib2
import StringIO
import csv
import matplotlib.pyplot as plt

#define start and end dates
startdate = '20121120'
enddate = '20121130'
# Read data from LOBO
response = urllib2.urlopen(''
data =
# We use StringIO to convert data into a StringIO object
# Learn more:
data = StringIO.StringIO(data)
# read the StringIO object as it was a file
r = csv.DictReader(data,

# Put the values into x, y1, and y2.
date= []
temp= []
salt= []
for row in r:
    date.append(row['date [AST]'])
    temp.append(row['temperature [C]'])
# Change the time strings into datetime objects
from datetime import datetime
DAT = []
for row in date:
    DAT.append(datetime.strptime(row,"%Y-%m-%d %H:%M:%S"))
#create figure
fig, ax =plt.subplots(1)
# Plot y1 vs x in blue on the left vertical axis.
plt.xlabel("Date [AST]")
plt.ylabel("Temperature [C]", color="b")
plt.tick_params(axis="y", labelcolor="b")
plt.plot(DAT, temp, "b-", linewidth=1)
plt.title("Temperature and Salinity from LOBO (Halifax, Canada)")

# Plot y2 vs x in red on the right vertical axis.
plt.ylabel("Salinity", color="r")
plt.tick_params(axis="y", labelcolor="r")
plt.plot(DAT, salt, "r-", linewidth=1)
#To save your graph
  1. Take a Screenshot of a web page and “Click” buttons in a web page 4 Replies
  2. 1D quiver plot – Surface currents – LOBO 1 Reply
  3. OTN Gliders (animated .gif) Leave a reply
  4. OTN Gliders (more advanced plotting) Leave a reply
  5. OTN Gliders (basic plotting) Leave a reply
  6. Bathymetry / Topography (SRTM30) 2 Replies
  7. Signal filtering (Butterworth filter) Leave a reply
  8. Whale distribution (OBIS SEAMAP) Leave a reply
  9. 2D histogram 7 Replies