# Arange in Julia

**URL:** <https://discourse.julialang.org/t/arange-in-julia/52239>\
**Category:** General Usage\
**Created:** [December 22, 2020, 6:47pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239 "2020-12-22T18:47:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [December 22, 2020, 6:47pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239/1 "2020-12-22T18:47:56Z")

</div>

What function is used as `arange` in Julia ? For example, if I want to manage the frequency of `xticks` in my plots.

In Python it works like:`xticks(arange(0, length(l_ticks)+1, 1))`.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [December 22, 2020, 6:52pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239/2 "2020-12-22T18:52:20Z")

</div>

Check out [`range`](https://docs.julialang.org/en/v1/base/math/#Base.range). Example:

```julia
julia> range(0,2,step=1) |> collect
3-element Array{Int64,1}:
 0
 1
 2

```

In most cases you won’t need the collect call, just using it here to display all values.

Note that you can also just write `0:1:2` (start:step:stop):

```julia
julia> 0:1:2 |> collect
3-element Array{Int64,1}:
 0
 1
 2

```

---

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [December 22, 2020, 7:18pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239/3 "2020-12-22T19:18:09Z")

</div>

It generates but the idea is just I wanted fewer xticks for example, what `0:2:24 |> collect` gives me even numbers. I need these numbers to be the xticks in the plot. However, it doesn’t work or it gives me dimension mismatched error. Below is simple data.

```nohighlight
price = [7.33, 7.42, 6.14, 5.77, 6.07, 9.44, 12.69, 15.97, 29.27, 23.86, 20.13, 19.60, 19.45, 19.09, 19.55, 20.16, 22.47, 43.11, 52.85, 34.01, 32.00, 23.91, 15.55, 13.85]
x_ticks=["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"]
l_ticks=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
plot(l_ticks,price);

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 22, 2020, 7:21pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239/4 "2020-12-22T19:21:24Z")

</div>

You specify the tick locations separately from the x coordinates of the data (which have to match the actual data), something like

```julia
plot(1:length(price), price, ticks=1:4:24)

```

IIRC. There is also an `xticks!` function.

---

<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:** [December 22, 2020, 7:28pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239/5 "2020-12-22T19:28:01Z")

</div>

And, of course, you can control `x` and `y` ticks independently:

```julia
julia> plot(rand(10),rand(10),xticks=0:0.2:1,xlims=(-0.5,1.5),yticks=0:0.5:1,ylims=(-2,2))

julia> savefig("./plot.png")

```

![plot](https://global.discourse-cdn.com/julialang/original/3X/f/e/fe7587fa7b29929fdf69392fbe9ce57b3eea4260.png)

---

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [December 22, 2020, 7:39pm UTC](https://discourse.julialang.org/t/arange-in-julia/52239/6 "2020-12-22T19:39:48Z")

</div>

Thanks!
