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

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 but haven’t found a relevant option. Are there such an option?

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

2 Likes

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

``````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

``````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.

@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

``````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.)

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