Last active
August 29, 2015 14:06
-
-
Save ahwillia/43c2cfb894f2bfec6760 to your computer and use it in GitHub Desktop.
Scatterplot matrix in julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Thanks to Joe Kington | |
# http://stackoverflow.com/questions/7941207/is-there-a-function-to-make-scatterplot-matrices-in-matplotlib | |
using PyPlot | |
function pairs(data) | |
(nobs, nvars) = size(data) | |
(fig, ax) = subplots(nvars, nvars, figsize=(8,8)) | |
subplots_adjust(hspace=0.05, wspace=0.05) | |
# Plot data | |
for i = 1:nvars | |
for j = 1:nvars | |
if i != j | |
ax[i,j][:plot](data[:,j],data[:,i],"ob",mfc="none") | |
else | |
ax[i,j][:hist](data[:,i]) | |
end | |
ax[i,j][:xaxis][:set_visible](false) | |
ax[i,j][:yaxis][:set_visible](false) | |
end | |
end | |
# Set tick positions | |
for i = 1:nvars | |
ax[i,1][:yaxis][:set_ticks_position]("left") | |
ax[i,end][:yaxis][:set_ticks_position]("right") | |
ax[1,i][:xaxis][:set_ticks_position]("top") | |
ax[end,i][:xaxis][:set_ticks_position]("bottom") | |
end | |
# Turn ticks on | |
cc = repmat([nvars, 1],int(ceil(nvars/2)),1) | |
for i = 1:nvars | |
ax[i,cc[i]][:yaxis][:set_visible](true) | |
ax[cc[i],i][:xaxis][:set_visible](true) | |
end | |
end | |
# Example | |
d = rand(100,6) | |
pairs(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment