2d histogram
python 2d hsitogram using matplotlib and pandas
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 12 11:20:19 2013
Edited by Emilio, 2013 Jun 12
@author: robertbrantonMBPro
"""
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Get data from ERDDAP server
resppd = pd.read_csv('http://nile.apl.washington.edu/erddap/tabledap/otnnepPSS2AnTags.csvp?length,weight')
# Scale for plotting
x=resppd['length (meters)'] * 100
y=resppd['weight (kg)'] * 1000
# -----------------------------------------------------------------
# Simple scatter plot
fig1 = plt.figure()
plt.plot(x,y,'.r')
plt.xlabel('length(cm)')
plt.ylabel('weight(gr)')
# Estimate the 2D histogram
H, xedges, yedges = np.histogram2d(x,y,bins=60)
H = np.rot90(H) # rotate
H = np.flipud(H) # flip
Hmasked = np.ma.masked_where(H==0,H) # Mask pixels with a value of zero
# 2D histogram using pcolor
fig2 = plt.figure()
plt.pcolormesh(xedges,yedges,Hmasked)
plt.xlabel('length(cm)')
plt.ylabel('weight(gr)')
cbar = plt.colorbar()
cbar.ax.set_ylabel('Counts')