GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.9k stars 250 forks source link

Plot Sizing & Exporting to Latex - Corrupted Axes Ticks/GridLines #613

Open neilpanchal opened 9 years ago

neilpanchal commented 9 years ago

I am using iPython/Jupyter notebook with Julia version 0.3.9. I am trying to a histogram that is generated using the following code:

my_plot = plot(
    layer(
        x=param,
        Geom.histogram,
        Theme(default_color = color(palette[1]),default_point_size=1px, highlight_width=0px)
    ),
    Scale.x_log10
)

The output in iPython notebook looks like this: screen shot 2015-06-23 at 5 48 29 pm

When I print the notebook using nbconvert to PDF (using the default latex template), I get an output like this. screen shot 2015-06-23 at 5 49 28 pm

The only problem is that the iPython notebook plot is tiny using default settings. I want to specify the size of the output in pixels or cm. So, I googled for a solution and came cross this thread:

http://julia-programming-language.2336112.n4.nabble.com/change-size-of-individual-plot-in-gadfly-under-IJulia-td14000.html

Quoting @dcjones

Hi Andrei, You can do this using the draw function, like: draw(SVG(20cm, 10cm), plot(...)) On Wednesday, February 11, 2015 at 3:42:47 PM UTC-8, Andrei Berceanu wrote: set_default_plot_size changes the default size of all following plots, but how can i set the size of a >certain plot individually?

Ok, so I simply changed by code to output as follows:

draw(SVGJS(20cm, 12cm), my_plot)

Output (as follows) looks great in iPython! screen shot 2015-06-23 at 5 47 59 pm

However, when I print again using nbconvert to PDF, I get this ugly mess. From the looks of it, the tick marks are pretty much arbitrarily spaced.

screen shot 2015-06-23 at 6 06 00 pm

Any suggestions on what is going on when I convert the notebook? I am not too familiar with the background processes that generate SVG.

dcjones commented 9 years ago

Interesting. Does the same thing happen if you use SVG instead of SVGJS?

With SVGJS grid lines and ticks are generated at multiple scales and hidden unless you zoom in or out. I suspect that the PDF conversion ignores the hidden attribute.

neilpanchal commented 9 years ago

@dcjones

ohhh...that makes sense. I tried it with SVG instead of SVGJS option and it worked fine!

I found another bug where using iPython notebook. When I roll over the plotting area, the grid lines appear to glitch and it is different every time I hover the cursor over it. See some examples:

screen shot 2015-06-24 at 8 14 04 am screen shot 2015-06-24 at 8 14 12 am screen shot 2015-06-24 at 8 13 53 am

After a few times, it stop glitching and the grid lines are constant. Is it because when I hover over, the grid lines animate/fade? Not sure but just wanted to report this as it appears to be related to JS implementation.

dcjones commented 9 years ago

What version of Gadfly are you using? I think I fixed this, but I probably haven't tagged a new version since doing so.

neilpanchal commented 9 years ago

@dcjones Gadfly: 0.3.12

dcjones commented 9 years ago

Oh yeah, I did fix this in https://github.com/dcjones/Gadfly.jl/commit/08716bfc6fb0570840397dc0361686905e102cfc. I should tag a new version soon.

neilpanchal commented 9 years ago

@dcjones Thanks Daniel. Is there any fix for SVGJS for printing in iPython? It would be nice to have dynamic plots displayed in the HTML notebook but it should switch to SVG method when printing statically.

dcjones commented 9 years ago

I'll look into it, but I suspect the fix will have to be in ipython/jupyter. It should really just respect the SVG visibility attribute.

neilpanchal commented 9 years ago

@dcjones Do you think I should file this issue @ https://github.com/JuliaLang/IJulia.jl

dcjones commented 9 years ago

When I print to PDF, it actually looks ok: screen shot 2015-06-25 at 12 28 57 pm

On the other hand, when I use the "download as PDF" feature the result is broken in a entirely different way: screen shot 2015-06-25 at 12 25 52 pm

How were you exporting the pdf?

neilpanchal commented 9 years ago

@dcjones The just used File > Download as > PDF via Latex (.pdf) option in iPython notebook.

dcjones commented 9 years ago

Ok, ipython uses Inkscape to convert SVG to PDF. So I think to boils down to an inkscape issue. If you have it installed, can you test if SVG from Gadfly looks right inkscape?

rodonn commented 8 years ago

I ran into this issue to. I wonder where the best place to document it so others have an easier time figuring it out.

To get File > Download as > PDF via Latex (.pdf) option in iPython notebook working with a Gadly plot I did the following: