Sort values on the y-axis from smallest to largest


Hello Everyone, as you see from my grap, my y axis is not sorted. How can I sort the y axix from minumum to maximum.

using Plots
using DataFrames
using CSV

df = CSV.read("D:/ölçüm.csv", DataFrame)
Zaman2_1 = df[:, 1]
Sensor1_Z_ekseni_grafik2_1 = df[:, 5]
fig_ölçüm_iki = plot(Zaman2_1, Sensor1_Z_ekseni_grafik2_1, yticks=true, size = (1600,800), title = "Z ekseni Grafik Line", yflip=false, xlabel="Zaman", ylabel="Z (Gs)")

Hi, and welcome to the Julia community!


Note that you can enclose your code in triple backticks (```), for proper formatting. See also Please read: make it easier to help you.


Considering the x-axis uses a decimal point and the y-axis a decimal comma, my guess is your df[:, 5] is parsed as a Vector{String}. If so, you could convert it to a Vector{Float64} using parse.(Float64, replace.(df[:, 5], ',' => ".")), which will first replace every (decimal) comma by a (decimal) point, and then convert all these Strings to Float64.

Once your y-values are floats, the y-axis should behave as you’d expect.

1 Like

If this is because you are in a country that uses , as the decimal separator you can tell CSV about this. From the docstring:

decimal='.': a Char indicating how decimals are separated in floats, i.e. 3.14 uses '.', or 3,14 uses a comma ','

so

df = CSV.read(“D:/ölçüm.csv”, DataFrame; decimal = `,`)

will read 1.234,56 as 1234.56.

2 Likes
julia> scatter(x_ekseni, y_ekseni, z_ekseni)
ERROR: ArgumentError:     Conversion failed for Scatter (With conversion trait PointBased()) with args: Tuple{Vector{String31}, Vector{String31}, Vector{String31}} .
    Scatter requires to convert to argument types Tuple{AbstractVector{<:Union{Point2, Point3}}}, which convert_arguments didn't succeed in.
    To fix this overload convert_arguments(P, args...) for Scatter or PointBased() and return an object of type Tuple{AbstractVector{<:Union{Point2, Point3}}}.`

Stacktrace:
 [1] conversion_pipeline(P::Type{Scatter}, used_attrs::Tuple{}, args::Tuple{Vector{…}, Vector{…}, Vector{…}}, kw_obs::Observable{Vector{…}}, args_obs::Tuple{Observable{…}, Observable{…}, Observable{…}}, user_attributes::Dict{Symbol, Any}, deregister::Vector{Observables.ObserverFunction}, recursion::Int64)
   @ Makie C:\Users\Gaming\.julia\packages\Makie\ux0Te\src\interfaces.jl:241
 [2] conversion_pipeline(P::Type{Scatter}, used_attrs::Tuple{}, args::Tuple{Vector{…}, Vector{…}, Vector{…}}, kw_obs::Observable{Vector{…}}, args_obs::Tuple{Observable{…}, Observable{…}, Observable{…}}, user_attributes::Dict{Symbol, Any}, deregister::Vector{Observables.ObserverFunction}, recursion::Int64)
   @ Makie C:\Users\Gaming\.julia\packages\Makie\ux0Te\src\interfaces.jl:233
 [3] conversion_pipeline(P::Type{Scatter}, used_attrs::Tuple{}, args::Tuple{Vector{String31}, Vector{String31}, Vector{String31}}, kw_obs::Observable{Vector{Pair{…}}}, args_obs::Tuple{Observable{Any}, Observable{Any}, Observable{Any}}, user_attributes::Dict{Symbol, Any}, deregister::Vector{Observables.ObserverFunction})
   @ Makie C:\Users\Gaming\.julia\packages\Makie\ux0Te\src\interfaces.jl:213
 [4] (Scatter)(user_args::Tuple{Vector{String31}, Vector{String31}, Vector{String31}}, user_attributes::Dict{Symbol, Any})
   @ Makie C:\Users\Gaming\.julia\packages\Makie\ux0Te\src\interfaces.jl:273
 [5] _create_plot(::Function, ::Dict{Symbol, Any}, ::Vector{String31}, ::Vararg{Vector{String31}})
   @ Makie C:\Users\Gaming\.julia\packages\Makie\ux0Te\src\figureplotting.jl:316
 [6] scatter(::Vector{String31}, ::Vararg{Vector{String31}}; kw::@Kwargs{})
   @ MakieCore C:\Users\Gaming\.julia\packages\MakieCore\rZ9WV\src\recipes.jl:510
 [7] scatter(::Vector{String31}, ::Vararg{Vector{String31}})
   @ MakieCore C:\Users\Gaming\.julia\packages\MakieCore\rZ9WV\src\recipes.jl:508
 [8] top-level scope
   @ REPL[13]:1
Some type information was truncated. Use `show(err)` to see complete types.

I got this error after I applied that code. Do I miss anything here?

All your columns are strings now, so it doesn’t look like this was the right decimal separator. I don’t have your csv file, so it’s hard to say what’s going wrong.

I corrected the formatting of your post. Note that a backquote ` is not the same as a quote ' and the triple backquote must be on a line by itself.

1 Like