1

I use the following code to produce a graph in Julia with Gadfly:

using Gadfly, Cairo, Fontconfig
p = plot(sin, 0, pi)
p |> PNG("sin_pi.png", 6inch, 4inch)

This is the graph that I get:

sine

The horizontal axis is not adjusted properly since there is a blank space at the end. However, if the indicated bounds of the horizontal axis are integers, there is no blank space. Consider the following example:

using Gadfly, Cairo, Fontconfig
p = plot(sin, 0, 4)
p |> PNG("sin_4.png", 6inch, 4inch)

enter image description here

I would guess that this is simply a bug, but I am completely new to Julia and Gadfly so I do not know if this is the intended behaviour. Is this a bug or is there a way to adjust how the range of the horizontal axis is determined?

Any help is much appreciated!

P.S. I use Julia v1.3.1 with Gadfly v1.2.0 on macOS 10.15.3. The results are the same if I just use

using Gadfly
plot(sin, 0, pi)
plot(sin, 0, 4)

but I am not sure if there is an easy way to incorporate an SVG file into my question.

Cm7F7Bb
  • 307
  • 2
  • 9

1 Answers1

1

There is an example in the Gadfly docs: http://gadflyjl.org/stable/gallery/coordinates/

Mattriks
  • 171
  • 4
  • That is interesting. So the second and the third argument of `plot` determines the range of the argument of the function but not the limits of the horizontal axis. We need to use `Coord.cartesian` to determine the limits of the horizontal axis and the limits of the horizontal axis are expanded up to the nearest integer by default. That is why we get this blank space. Is that correct? – Cm7F7Bb Mar 05 '20 at 21:46