Skip to content

Commit

Permalink
add style for image and histogram2 plots
Browse files Browse the repository at this point in the history
  • Loading branch information
mykelk committed Mar 9, 2016
1 parent 8c89690 commit 59db175
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/PGFPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ function plotHelper(o::IOBuffer, p::Image)
if p.zmin == p.zmax
error("Your colorbar range limits must not be equal to each other.")
end
println(o, "\\addplot [point meta min=$(p.zmin), point meta max=$(p.zmax)] graphics [xmin=$(p.xmin), xmax=$(p.xmax), ymin=$(p.ymin), ymax=$(p.ymax)] {$(p.filename)};")
if p.style != nothing
println(o, "\\addplot [$(p.style), point meta min=$(p.zmin), point meta max=$(p.zmax)] graphics [xmin=$(p.xmin), xmax=$(p.xmax), ymin=$(p.ymin), ymax=$(p.ymax)] {$(p.filename)};")
else
println(o, "\\addplot [point meta min=$(p.zmin), point meta max=$(p.zmax)] graphics [xmin=$(p.xmin), xmax=$(p.xmax), ymin=$(p.ymin), ymax=$(p.ymax)] {$(p.filename)};")
end
end

# plot option string and contents; no \begin{axis} or \nextgroupplot
Expand Down
13 changes: 7 additions & 6 deletions src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ type Image <: Plot
zmax::Real
colorbar::Bool
colormap::ColorMaps.ColorMap
function Image{T <: Real}(A::Matrix{T}, xrange::RealRange, yrange::RealRange; filename=nothing, colorbar=true, colormap=ColorMaps.Gray(), zmin=nothing, zmax=nothing)
style
function Image{T <: Real}(A::Matrix{T}, xrange::RealRange, yrange::RealRange; filename=nothing, colorbar=true, colormap=ColorMaps.Gray(), zmin=nothing, zmax=nothing, style=nothing)
global _imgid
if filename == nothing
id=myid()*10000000000000+_imgid
Expand All @@ -193,19 +194,19 @@ type Image <: Plot
else
write(ColorMaps.RGBArray(colormap), A, filename)
end
new(filename, xrange[1], xrange[2], yrange[1], yrange[2], zmin, zmax, colorbar, colormap)
new(filename, xrange[1], xrange[2], yrange[1], yrange[2], zmin, zmax, colorbar, colormap, style)
end
function Image(f::Function, xrange::RealRange, yrange::RealRange; filename=nothing, colorbar=true, colormap=ColorMaps.Gray(), zmin=nothing, zmax=nothing, xbins=100, ybins=100)
function Image(f::Function, xrange::RealRange, yrange::RealRange; filename=nothing, colorbar=true, colormap=ColorMaps.Gray(), zmin=nothing, zmax=nothing, xbins=100, ybins=100, style=nothing)
x = linspace(xrange[1], xrange[2], xbins)
y = linspace(yrange[1], yrange[2], ybins)
(X, Y) = meshgrid(x, y)
A = map(f, X, Y)
A = flipdim(A, 1)
Image(A, xrange, yrange, filename=filename, colorbar=colorbar, colormap=colormap, zmin=zmin, zmax=zmax)
Image(A, xrange, yrange, filename=filename, colorbar=colorbar, colormap=colormap, zmin=zmin, zmax=zmax, style=style)
end
end

function Histogram2{A<:Real, B<:Real}(x::Vector{A}, y::Vector{B}; xmin=minimum(x), xmax=maximum(x), ymin=minimum(y), ymax=maximum(y), xbins=50, ybins=50, density=false, filename=nothing, colorbar=true, colormap=ColorMaps.Gray(), zmin=nothing, zmax=nothing)
function Histogram2{A<:Real, B<:Real}(x::Vector{A}, y::Vector{B}; xmin=minimum(x), xmax=maximum(x), ymin=minimum(y), ymax=maximum(y), xbins=50, ybins=50, density=false, filename=nothing, colorbar=true, colormap=ColorMaps.Gray(), zmin=nothing, zmax=nothing, style=nothing)
ex = linspace(xmin, xmax, xbins+1)
ey = linspace(ymin, ymax, ybins+1)
ex, ey, M = hist2d(hcat(y, x), ey, ex)
Expand All @@ -214,7 +215,7 @@ function Histogram2{A<:Real, B<:Real}(x::Vector{A}, y::Vector{B}; xmin=minimum(x
scale = xbins * ybins / ((xmax-xmin) * (ymax-ymin) * sum(M))
M = M * scale
end
Image(M, (xmin, xmax), (ymin, ymax), filename=filename, colorbar=colorbar, colormap=colormap, zmin=zmin, zmax=zmax)
Image(M, (xmin, xmax), (ymin, ymax), filename=filename, colorbar=colorbar, colormap=colormap, zmin=zmin, zmax=zmax, style=style)
end

end # end plot module

0 comments on commit 59db175

Please sign in to comment.