# Plot: uniform tic marks, numeric labels at every other tic mark

**URL:** <https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [November 10, 2022, 2:29pm UTC](https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052 "2022-11-10T14:29:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [November 10, 2022, 2:29pm UTC](https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052/1 "2022-11-10T14:29:50Z")

</div>

As I understand, minor tic marks are shorter than major ones, and major ones have associated numeric labels.

Now, what I want to achieve is to have tic marks with an equal length but the numeric labels are placed at every other tic mark.

My present idea is either 1) to plot minor tic marks with the same length as the major tic mark or 2) to place the numeric labels at every other major tic mark without minor tic marks.

I’m looking at [Plot Attributes · Plots](https://docs.juliaplots.org/latest/generated/attributes_plot/) but haven’t found a relevant option. Are there such an option?

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [November 10, 2022, 3:17pm UTC](https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052/2 "2022-11-10T15:17:18Z")

</div>

You can do something like `xticks = (1:10, [string(i) for i in 1:10 if isodd(i)])`.

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [November 11, 2022, 8:11am UTC](https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052/3 "2022-11-11T08:11:48Z")

</div>

@BeastyBlacksmith Thanks! Taking your idea, I confirm this strategy

```julia
xt = 1:10
xticks = (xt, map(i -> isodd(i) ? string(i) : "", xt) )

```

works. (You forgot to take care of the labels when `i` is even.)

But, does this means that we could have instead redefined `xformatter`, as

```julia
plot( . . . ; xformatter=i->isodd(i) ? string(i) : "", . . . )

```

? (Not tested. Also, I’m not saying this is better.)

Also, it was surprising to me that conceptually, “ticks” _include_ the numeric labels in the `Plots` framework.

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [November 11, 2022, 8:46am UTC](https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052/4 "2022-11-11T08:46:05Z")

</div>

@BeastyBlacksmith Oh but, it seems to me that `string()` isn’t the right function to convert a number to a `String`.

`string(-1)`, for example, produces “-1” (hyphen “1”), but when I examine other plots Julia has produced, I see that the unicode _minus_ character is probably used for negative numbers: “−1”. (I haven’t verified this.)

I’ll find out what the proper conversion function is. As a stopgap solution, I use

```julia
num2str(a) = (a >= 0) ? string(a) : "−" * string(-a)

```

in place of `string()`. The “−” character is the unicode minus symbol. (I don’t know what would happen to negative zero of IEEE floating point numbers.)

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [November 11, 2022, 10:11am UTC](https://discourse.julialang.org/t/plot-uniform-tic-marks-numeric-labels-at-every-other-tic-mark/90052/5 "2022-11-11T10:11:45Z")

</div>

> [@ryofurue](#):
>
> But, does this means that we could have instead redefined `xformatter`, as
> 
> ```julia
> plot( . . . ; xformatter=i->isodd(i) ? string(i) : "", . . . )
> 
> ```
> 
> ?

That should work too, depends on whether you want to control the locations of the ticks or not.
