# How to increase plot width in Julia Plots.jl without increasing tick line width and the gap between tick and tick axis

**URL:** <https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [May 22, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660 "2021-05-22T23:37:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [May 22, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/1 "2021-05-22T23:37:02Z")

</div>

Hello,

I want to plot many data points whose x values are very close to each other. To be able to separate them out a little more so that they can be seen more clearly, I want to increase the plot width (it can be much larger than the paper size; I don’t need to print it). I tried the MWE shown below. The problem is that this creates (1) Long tick lines for the y-axis; and (2) Big gap between the tick labels and the axis line.

My main question is:

How can I manipulate both these settings in Plots.jl so that this does not happen? I want the tick labels next to the axis line and tick lines to be smaller. I would really appreciate any help.

Thank you.

```julia
module CodeQuestion

import Plots
import Dates
import StatsBase; Sb = StatsBase

function plotdata()
    xtickvals = Dates.DateTime(2020,1,4,0,0,0):Dates.Second(3600):Dates.DateTime(2020,1,5,0,0,0) |> collect
    xvals = Dates.DateTime(2020,1,4,0,0,0):Dates.Second(10):Dates.DateTime(2020,1,5,0,0,0) |> collect
    xvalsplt = Sb.sample(xvals, 6000, replace = false) |> sort
    numobs = length(xvalsplt)
    yvals = [rand(-5:-2) for i = 1:numobs]

    Plots.plot( xvalsplt, yvals, 
                seriestype = :scatter, 
                label = :none, 
                xticks = xtickvals,
                yticks = -10:2.5:0,
                ytickfonthalign = :left,
                left_margin = 20Plots.mm,
                bottom_margin = 40Plots.mm,
                xrotation = 90,
                xlims = [Dates.value(xtickvals[1]), Dates.value(xtickvals[end])],
                ylims = [-10, 1],
                markersize = 4,
                markerstrokecolor = "gray",
                marketstrokewidth = 0.5,
                size = (7200,500))
    Plots.savefig("fig_temp.pdf")
end

end ## end module

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 23, 2021, 12:51am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/2 "2021-05-23T00:51:20Z")

</div>

I don’t know how to answer your specific question, but maybe I can suggest an alternative. In a Pluto notebook you can add a slider to change the x limits and walk over your data:

[https://github.com/lmiq/Work/raw/master/ezgif.com-gif-maker.png](https://github.com/lmiq/Work/raw/master/ezgif.com-gif-maker.png)

```julia
# ╔═╡ bf4ce15c-bb5d-11eb-1544-59e5da109424
using Plots

# ╔═╡ 42e5ad87-62c2-46ce-9c07-3dcc2fa5a024
using Dates

# ╔═╡ 5cf7d1ac-35cd-42fc-b85e-d0934759da69
using StatsBase

# ╔═╡ 24f8bcca-dca8-48f2-80b3-f22200c94f00
xvals = Dates.DateTime(2020,1,4,0,0,0):Dates.Second(10):Dates.DateTime(2020,1,5,0,0,0) |> collect

# ╔═╡ cf88a07e-bb3e-48a4-89a3-36c16bdd00d6
xvalsplt = sample(xvals, 6000, replace = false) |> sort

# ╔═╡ 689c1cb4-1f3a-44c6-86e0-ac1df24e0142
numobs = length(xvalsplt)

# ╔═╡ a578f4dc-d87d-4739-a3d7-66bd4c0f0475
yvals = [rand(-5:-2) for i = 1:numobs]

# ╔═╡ db52bef8-fd6f-4016-a210-a98f3fe1e53b
scatter(xvals,yvals,xlim=[Dates.value(xvals[imin]), Dates.value(xvals[imin+irange])],xrotation=60,label="")

# ╔═╡ 91e505c9-bd5f-4955-bb68-7a3eb467e53a
@bind irange html"<input type='range' min=1 max=length(xvals)>"

# ╔═╡ de5d832e-27e4-480a-b6fa-75e9dd9e4b7e
@bind imin html"<input type='range' min=1 max=length(xvals)>"

# ╔═╡ 350d06f0-74a6-4e71-bd56-3878a8588fb8

```

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [May 23, 2021, 1:34am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/3 "2021-05-23T01:34:40Z")

</div>

> [@lmiq](#):
>
> `@bind imin html"<input type='range' min=1 max=length(xvals)>"`

Thank you very much LeandroMartinez98. This might be an interesting avenue. Still it would be great to learn how to adjust tick position of labels. But will explore this more. I have not used Pluto.jl before. So this is a great way to start exploring it.

Thanks again!

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 23, 2021, 2:15am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/4 "2021-05-23T02:15:39Z")

</div>

(could you see the animation? - just curiosity, I am not sure how to share it here).

To explore the data as you are trying to, it seems a nice option.

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [May 23, 2021, 2:58am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/5 "2021-05-23T02:58:44Z")

</div>

I did see it. It is very cool. However, I need to look more into sharing options with it, and see if it would be as easy as sharing a static PDF. But for my own consumption that would have been a good option.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [May 23, 2021, 3:57am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/6 "2021-05-23T03:57:52Z")

</div>

Different backends behave differently. For example, InspectDR doesn’t _ **stretch** _ your plot as an image the way the GR backend appears to be doing. Instead, it uses the `size = (7200,500)` argument to _ **specify the canvas size** _, and always keeps the same tick length (which is specified in its “Layout” structures).

### GR output (Default in Plots.jl)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/6/66d52edc92aa949b9c2d0c748e6d50f53062873e.png)

### InspectDR output

If you add the InspectDR package, and the code needed to use it, you get the following:

```julia-auto
import StatsBase; Sb = StatsBase
import InspectDR

function plotdata()
    Plots.inspectdr() #Choose InspectDR backend
    #Plots.gr() #Choose GR backend
    xtickvals = Dates.DateTime(2020,1,4,0,0,0):Dates.Second(3600):Dates.DateTime(2020,1,5,0,0,0) |> collect

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/2/32a31e4bdd74070131f9b422388e692ef0c6bb82.png)

Note that InspectDR doesn’t rotate the x-tick labels at the moment - but I think that it probably works out for the best in this case.

### Other backends

You might want to experiment with other backends if you don’t like the InspectDR output. InspectDR is not _as_ customizable as other backends.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [May 23, 2021, 4:30am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/7 "2021-05-23T04:30:03Z")

</div>

> [@curious](#):
>
> However, I need to look more into sharing options with it, and see if it would be as easy as sharing a static PDF.

### Sharing PDF

Sharing a PDF is definitely the easiest way to guarantee everyone can read your plots.

### Alternative: Sharing .HDF5 plots

Plots.jl has a “HDF5 backend” that allows you to save plots+data as a single .hdf5 file. Using this “backend”, your colleagues can display plots with a simple Julia script without having to re-run your whole algorithm/simulation.

To do this, they would have to install Julia+Plots.jl, and you would have to provide the .hdf5 plot data & a simple load script resembling the one in:  
 → [http://docs.juliaplots.org/latest/backends - HDF5-Plots](http://docs.juliaplots.org/latest/backends/#%5BHDF5%5D(https://github.com/JuliaIO/HDF5.jl)-(HDF5-Plots))

**Caveat:** HDF5-Plots is not yet a proper versioned file format. That means your colleagues should use the same version of Plots.jl you used to save the plot. Otherwise, there is a higher chance the data structures won’t match - and the HDF5-Plots backend won’t know how to read the data back in correctly.

### Alternative: Hosting a Pluto session

If Pluto works somewhat like Jupyter, you should be able to let colleagues connect to your own Pluto session. Of course, you need to have a machine running Pluto to host this session whenever they need to explore the data (which is non-ideal).

But, by combining this with the HDF5-Plots solution, coworkers wouldn’t need to run your whole algorithm/simulation either.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 23, 2021, 4:47am UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/8 "2021-05-23T04:47:58Z")

</div>

These `plotly` solutions [1](https://stackoverflow.com/questions/61782622/plotly-how-to-add-a-horizontal-scrollbar-to-a-plotly-express-figure) or [2](https://community.plotly.com/t/add-scrolling-options-to-plots/9493/7) look/sound good.

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [May 23, 2021, 12:08pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/9 "2021-05-23T12:08:12Z")

</div>

I haven’t got a direct answer to your question: the figure is super long and it may not be a great PDF to share, but you’ll know best. Here’s what I can suggest: Go to [the Github Plots repository and look inside the `scr` directory for file `args.jl`](https://github.com/JuliaPlots/Plots.jl/blob/master/src/args.jl)

Plenty of goodies to play around with. To identify which does what, you can change its color and increase the linewidth. I can’t see an option to control tick lengths though (but do read on).

```
const _axis_defaults = KW(
    :guide => "",
    :guide_position => :auto,
    :lims => :auto,
    :ticks => :auto,
    :scale => :identity,
    :rotation => 0,
    :flip => false,
    :link => [],
    :tickfontfamily => :match,
    :tickfontsize => 8,
    :tickfonthalign => :hcenter,
    :tickfontvalign => :vcenter,
    :tickfontrotation => 0.0,
    :tickfontcolor => :match,
    :guidefontfamily => :match,
    :guidefontsize => 11,
    :guidefonthalign => :hcenter,
    :guidefontvalign => :vcenter,
    :guidefontrotation => 0.0,
    :guidefontcolor => :match,
    :foreground_color_axis => :match, # axis border/tick colors,
    :foreground_color_border => :match, # plot area border/spines,
    :foreground_color_text => :match, # tick text color,
    :foreground_color_guide => :match, # guide text color,
    :discrete_values => [],
    :formatter => :auto,
    :mirror => false,
    :grid => true,
    :foreground_color_grid => :match, # grid color
    :gridalpha => 0.1,
    :gridstyle => :solid,
    :gridlinewidth => 0.5,
    :foreground_color_minor_grid => :match, # grid color
    :minorgridalpha => 0.05,
    :minorgridstyle => :solid,
    :minorgridlinewidth => 0.5,
    :tick_direction => :in,
    :minorticks => false,
    :minorgrid => false,
    :showaxis => true,
    :widen => true,
    :draw_arrow => false,
)

```

If you look inside `axes.jl` in the same directory, function `axis_drawing_info` sets up the axes and the ticks, starting on line 650. It looks like some lengths are hard-coded. You’ll see numbers like `0.012` and `0.006`, if you really want it, you could try to change these values and see if it works for you. All the best! 😅

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [May 23, 2021, 12:24pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/10 "2021-05-23T12:24:07Z")

</div>

Thank you all to your replies. A lot to digest here. I will explore these and get back. Thank you again for the pointers.

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [May 25, 2021, 5:59pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/11 "2021-05-25T17:59:18Z")

</div>

For now I decided to go with `matplotlib` since it did what I wanted much more easily. But thanks for pointers to Plotly. When I have more time, the zooming/panning functionality is more helpful there. Thanks everyone for your suggestions.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 25, 2021, 7:05pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/12 "2021-05-25T19:05:45Z")

</div>

> [@curious](#):
>
> zooming/panning functionality

Actually that was an easier answer, `using Plots; pyplot()`. At least here it opens an interactive plot which an be zoomed and dragged:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/f/9ffdb3f646695b8fc62f601301d448a8fd00d0f0.png)

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [May 27, 2021, 12:18pm UTC](https://discourse.julialang.org/t/how-to-increase-plot-width-in-julia-plots-jl-without-increasing-tick-line-width-and-the-gap-between-tick-and-tick-axis/61660/13 "2021-05-27T12:18:11Z")

</div>

Thank you! Will try this out. Really appreciate your help.
