N. Virgo
N. Virgo

Reputation: 8439

Log axis appearance in julia/Plots

Here is a plot generated by julia's Plots library, using the xaxis=:log attribute:

enter image description here

The plot has evenly spaced tick marks, with labels like 10^0.25. This might be useful sometimes, but I find it a bit confusing for this plot, because most people don't know the value of 10^0.25 without looking it up.

I would prefer the x axis to have logarithmically spaced ticks, representing uniform intervals of the quantity on the x axis. Here's a quick example to show what I mean, generated using semilogx in Python's matplotlib lirary:

enter image description here

In this plot the x axis has ticks at x=1, x=2, x=3 etc., which I find more useful for the figures I'm generating. Can this be achieved in julia using Plots?

Upvotes: 7

Views: 6012

Answers (1)

hckr
hckr

Reputation: 5583

As it has been told in the discourse topic, the default tick behavior (for most backends) is different than what you expected.

There is a way you can achieve the tick behaviour you want. You can manually set tick positions and tick labels through xticks (yticks or zticks) argument.

For example the following snippet will put ticks at equally spaced points as you wanted in your post.

x = 1:0.1:10;
y = rand(length(x));

plot(x, y, xscale=:log10, xticks=(1:10, 1:10))

The first element of the tuple is for the location of the ticks and the second is for the labels. Although I used a range object for labels, you can use array of Strings or LaTeXStrings etc.

You might also want to take a look at minorticks (xminorticks for your case) and minorgrid attributes in the Julia Plots documentation.

Upvotes: 7

Related Questions