juliajulia-plots

Negative exponent in plot in Julia


I have data with very small values

A =[1.1222557035765826e-7, 2.651246968143401e-7, 1.7965534845544633e-7, 6.726776330241659e-7, 1.3723877581050262e-7, 2.392303846597451e-7, 1.7973640211865906e-7, 6.872377806439872e-7, 1.6561887217935582e-7, 6.478555982586488e-7, 2.8740164125831344e-8, 1.3134595362998213e-8, 7.246216395795657e-7, 5.546199071784553e-7, 7.228658562485518e-7, 3.0842483138432094e-8, 1.6105574416294378e-8, 7.601753721421415e-7];

My problem is that when I plot it, I have the issue the negative exponent is not presented correctly.

using Plots
using Printf
using ColorSchemes
using Serialization
using LaTeXStrings

aplot = plot();
plot!(aplot, dt*(1:nTimeSteps), ϵHTrunc_t_max, label=L"\Omega = %$OMEGA, \, \textrm{max. err.}") 
savefig(aplot, OUTPUT_PATH * FILES * "_H_trunc_err_t.pdf")

enter image description here


Solution

  • Basically, you are having a problem with the negative exponent is that maybe they aren't being displayed accurately in the plot might be related to the way the values are displayed on the y-axis. Use the Plots library, to format the y-axis to ensure the exponents are displayed correctly. You can use the formatter attribute in the Plots library to format the axis ticks. The yformatter = :scientific could display the negative exponents.

    I have fixed your following code, and I have pasted it down below.

    using Plots
    using Printf
    using ColorSchemes
    using Serialization
    using LaTeXStrings
    
    # Sample data
    A = [1.1222557035765826e-7, 2.651246968143401e-7, 1.7965534845544633e-7, 6.726776330241659e-7, 1.3723877581050262e-7, 2.392303846597451e-7, 1.7973640211865906e-7, 6.872377806439872e-7, 1.6561887217935582e-7, 6.478555982586488e-7, 2.8740164125831344e-8, 1.3134595362998213e-8, 7.246216395795657e-7, 5.546199071784553e-7, 7.228658562485518e-7, 3.0842483138432094e-8, 1.6105574416294378e-8, 7.601753721421415e-7]
    
    # Simulated time steps (assuming dt and nTimeSteps are defined)
    dt = 1.0  # Define your time step appropriately
    nTimeSteps = length(A)
    time_steps = dt * (1:nTimeSteps)
    
    
    aplot = plot()
    plot!(aplot, time_steps, A, label=L"\Omega = %$OMEGA, \, \textrm{max. err.}", yformatter = :scientific)
    
    
    OUTPUT_PATH = "path/to/output/"  
    FILES = "filename"  
    savefig(aplot, OUTPUT_PATH * FILES * "_H_trunc_err_t.pdf")