I made this helper function a while back to display images using Gadfly:

function imshow(x, title::String="", units::String="", args...)

  is, js, values = findnz(x)

  m, n = size(x)

  df = DataFrames.DataFrame(i=is, j=js, value=values)

  plot(df, x="j", y="i", color="value",

         Coord.cartesian(yflip=true, fixed=true)

       , Scale.x_continuous(minvalue=0.5, maxvalue=n+0.5)

       , Scale.y_continuous(minvalue=0.5, maxvalue=m+0.5)

       , Geom.rectbin, Stat.identity

       , Guide.title(title) , Guide.colorkey(units)

       , Guide.XLabel(""), Guide.YLabel("")

       , Guide.xticks(ticks=[1,n]), Guide.yticks(ticks=[1,m])

       , Theme(panel_fill=color("black"), grid_line_width = 0inch)

       , args...)

end


On Friday, February 6, 2015 at 4:34:45 PM UTC-6, Andrei Berceanu wrote:
>
> The only thing keeping me from migrating from PyPlot to Gadfly is the lack 
> of 2D plotting abilities. To exemplify, I used the following code to 
> generate the attached image with PyPlot (here data is a 2d array):
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *fig, ax = plt.subplots(figsize=(4, 4))img = ax[:imshow](data, 
> origin="upper", ColorMap("hot"), 
> interpolation="none",                                           
> extent=[x[1], x[end], x[1], x[end]]) ax[:set_ylim](x[1], 
> x[end]) ax[:set_xlim](x[1], 
> x[end]) ax[:set_xlabel](L"$p_x$") ax[:set_ylabel](L"$p_y$") tks = [-3., 
> -1.5, 0, 1.5, 
> 3.] ax[:xaxis][:set_ticks](tks) ax[:yaxis][:set_ticks](tks) cbar = 
> fig[:colorbar](img, shrink=0.8, aspect=20, 
> fraction=.12,pad=.02) cbar[:ax][:tick_params](labelsize=7) 
> fig[:savefig]("fig_berry_bz", 
> bbox_inches="tight")*
>
> What is the current alternative for obtaining such a plot using Gadfly? 
> Are there plans for getting similar functionality anytime soon?
>

Reply via email to