Gadfly.jl icon indicating copy to clipboard operation
Gadfly.jl copied to clipboard

Geom.rectbin square

Open montyvesselinov opened this issue 7 years ago • 7 comments

How it can be imposed that the rectbin's are squares?

montyvesselinov avatar Oct 06 '16 14:10 montyvesselinov

Have you tried passing Coord.cartesian(fixed=true)? http://gadflyjl.org/stable/lib/coords/coord_cartesian.html#Coord.cartesian-1

tlnagy avatar Oct 06 '16 15:10 tlnagy

using Gadfly
using DataFrames
m = vcat([ [x y] for x=1:10, y=1:10 ]...)
D = vcat([DataFrame(x=m[:,1], y=m[:,2], z=rand(100), row=r, col=c) for r in ["d","e","f"], c in ["a","b","c"]]...)

mytheme = Theme(major_label_font_size=14pt, minor_label_font_size=12pt,
    key_title_font_size=16pt, key_label_font_size=12pt)
cscale = Scale.lab_gradient(colorant"green", colorant"yellow", colorant"red")
coord = Coord.cartesian(xmin=1, ymin=1, xmax=10, ymax=10, fixed=true, aspect_ratio=1)

p = plot(D, x=:x, y=:y, color=:z, xgroup = :col, ygroup=:row,
    Geom.subplot_grid(coord, Geom.rectbin()), 
    Scale.color_continuous(colormap=cscale), 
    Guide.xlabel("Sources"), Guide.ylabel("Species"),
    mytheme)

here is the example, i was given. it does not seem to work.

montyvesselinov avatar Oct 06 '16 16:10 montyvesselinov

This looks like a bug. It seems like there is an issue with Coord.subplot_grid respecting Coord.cartesian's fixed aspect ratio request.

tlnagy avatar Oct 06 '16 16:10 tlnagy

Let me know if I can help. On Thu, Oct 6, 2016 at 10:25 AM Tamas Nagy [email protected] wrote:

This looks like a bug. It seems like there is an issue with Coord.subplot_grid respecting Coord.cartesian's fixed aspect ratio request.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dcjones/Gadfly.jl/issues/912#issuecomment-252015123, or mute the thread https://github.com/notifications/unsubscribe-auth/AFXxeLnjS1Qe7SHd121iwOZoHG6JQ8xRks5qxSEDgaJpZM4KP-kf .

-monty

montyvesselinov avatar Oct 07 '16 00:10 montyvesselinov

Any help is appreciated! Maybe try looking at the subplot render function: https://github.com/dcjones/Gadfly.jl/blob/cb28d6aca6b031d01e44146799e520b8bb0d349b/src/geom/subplot.jl#L139

tlnagy avatar Oct 07 '16 01:10 tlnagy

I'm having the same issue! Has a workaround been found by now?

Vectornaut avatar Feb 12 '21 22:02 Vectornaut

I just encountered this issue. My work-around is to manually pass the correct canvas dimensions to set_default_plot_size as well as Coord.cartesian(fixed = true). Here is the revised (and formatted) version of the example from @montyvesselinov, tested on JJulia 1.8.5, and Gadfly v1.3.4.

using Gadfly
using DataFrames
m = vcat( [ [x y] for x = 1:10, y = 1:10 ]... )
D = vcat(
    [
        DataFrame(
            x = m[:,1],
            y = m[:,2],
            z = rand(100),
            row = r,
            col = c,
        ) for r in ["d","e","f"], c in ["a","b","c"]
    ]...
)

mytheme = Theme(
    major_label_font_size = 14pt,
    minor_label_font_size = 12pt,
    key_title_font_size = 16pt,
    key_label_font_size = 12pt,
)

cscale = Scale.lab_gradient(colorant"green", colorant"yellow", colorant"red")

coord = Coord.cartesian(
    xmin = 1,
    ymin = 1,
    xmax = 10,
    ymax = 10,
    fixed = true,
    aspect_ratio = 1,
)

# Work-around material starts.
N_x1 = 10 # change this to reflect the dimension of your data.
N_x2 = 10 # change this to reflect the dimension of your data.
scale_factor = 30 # the number 30 is arbitrary.
set_default_plot_size(N_x1*50px, N_x2*50px) #(vertical, horizontal) # the number 50 is arbitrary.
# Work-around material ends

p = plot(
    D,
    x = :x,
    y = :y,
    color = :z,
    xgroup  =  :col,
    ygroup = :row,
    Geom.subplot_grid(coord, Geom.rectbin()), 
    Scale.color_continuous(colormap=cscale), 
    Guide.xlabel("Sources"),
    Guide.ylabel("Species"),
    mytheme,
)

display(p)
using Gadfly
using DataFrames
m = vcat([ [x y] for x=1:10, y=1:10 ]...)
D = vcat([DataFrame(x=m[:,1], y=m[:,2], z=rand(100), row=r, col=c) for r in ["d","e","f"], c in ["a","b","c"]]...)

mytheme = Theme(major_label_font_size=14pt, minor_label_font_size=12pt,
    key_title_font_size=16pt, key_label_font_size=12pt)
cscale = Scale.lab_gradient(colorant"green", colorant"yellow", colorant"red")
coord = Coord.cartesian(xmin=1, ymin=1, xmax=10, ymax=10, fixed=true, aspect_ratio=1)

p = plot(D, x=:x, y=:y, color=:z, xgroup = :col, ygroup=:row,
    Geom.subplot_grid(coord, Geom.rectbin()), 
    Scale.color_continuous(colormap=cscale), 
    Guide.xlabel("Sources"), Guide.ylabel("Species"),
    mytheme)

here is the example, i was given. it does not seem to work.

RoyCCWang avatar Apr 15 '23 03:04 RoyCCWang