# Setting X Axis Using Plots

**URL:** <https://discourse.julialang.org/t/setting-x-axis-using-plots/103957>\
**Category:** Visualization\
**Created:** [September 17, 2023, 8:20pm UTC](https://discourse.julialang.org/t/setting-x-axis-using-plots/103957 "2023-09-17T20:20:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eweiss](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@eweiss](https://discourse.julialang.org/u/eweiss)\
**Post date:** [September 17, 2023, 8:20pm UTC](https://discourse.julialang.org/t/setting-x-axis-using-plots/103957/1 "2023-09-17T20:20:29Z")

</div>

I’m trying to plot stock prices which are daily but not on weekends. When I run this code

```julia
using Dates, DataFrames, Plots
df = DataFrame(Date=today()+Month(-1):Day(1):today(), rtn = rand(Float64, 32))
ticks = round.(df.Date, Week(1)) |> unique
delete!(df, [10, 11, 17, 18])
println(df)
       plt = Plots.plot(df.Date, df.rtn,
             xlabel = "Date",
             ylabel = "Cumulative Return",
             xticks = (ticks, Dates.format.(ticks, "mm/dd/yy")),
             xlims = Dates.value.([df.Date[1], df.Date[end]]),
             xrot = 60,
             color = :red,
             size=(600,400)
             )
        display(plt)

```

The labels for the x axis go off the scale. Shouldn’t xlim take care of this?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 18, 2023, 8:13am UTC](https://discourse.julialang.org/t/setting-x-axis-using-plots/103957/2 "2023-09-18T08:13:27Z")

</div>

No, the two are independent of each other, consider:

```julia
julia> plot(rand(5), 
            xlims = (0, 3), xticks = (1:0.1:4, string.(1:0.1:4)), 
            right_margin = 20Plots.mm, xrot = 50)

```

which gives

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

here I’ve deliberately made the problem worse by adding to the `right_margin`. You see that as long as there are ticklabels provided in `xticks` and there’s space on the figure (which I control here by `right_margin`), ticks will be shown.
