Search code examples
juliaaxis-labelsscientific-notationplots.jl

JuliaLang plot with large xtick label numbers is displayed with too many figures in scientific notation and malformed exponent


I am using Plots.jl with the default GR() plotting backend rather than pyplot from JuliaLang. The x-axis tick numbers are in the thousands and the series plot produced uses scientific notation wiki examples to display these numbers on the x-axis. Too many decimal points are given which is understandable since the axis point chosen is set by the program, but even for 1.00000x10 these trailing zeros are printed. Below is an example and a mistake in the exponentiation is produced. How can this be fixed. The fontfamily was even changed to see if the effect is removed but it remains. (xticks=1:step:final) enter image description here


Solution

  • You can use xformatter to change the format of the ticks (source):

    using Plots
    let n_samples = 80,
        d = Plots.fakedata(n_samples,1),
        i = collect(1:n_samples) .* 1e10
        plot(i,d, 
             xformatter = x->string(Int(x/1e10),"*pow10"))
    end
    

    This doesn't seem to be in the docs.