Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tick formatter with functions returning numerical values #4618

Merged
merged 2 commits into from
Jan 6, 2023

Conversation

daschw
Copy link
Member

@daschw daschw commented Jan 4, 2023

Some recent changes introduced a bug when providing a function that returns numerical values to the axis formatter:

julia> plot(1:10, yformatter=y -> 1e3y)
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: MethodError: Cannot `convert` an object of type Float64 to an object of type String
Closest candidates are:
  convert(::Type{String}, ::String) at essentials.jl:218
  convert(::Type{T}, ::T) where T<:AbstractString at strings/basic.jl:231
  convert(::Type{T}, ::AbstractString) where T<:AbstractString at strings/basic.jl:232
  ...
Stacktrace:
   [1-8]  internal
       @ Base, Unknown
     [9] convert(#unused#::Type{Vector{String}}, a::Vector{Float64})
       @ Base ./array.jl:617
    [10] optimal_ticks_and_labels(ticks::Nothing, alims::Tuple{Float64, Float64}, scale::Symbol, formatter::Function)
       @ Plots ~/.julia/dev/Plots/src/axes.jl:199
    [11] get_ticks(::Symbol, ::Vector{Float64}, ::Vector{Any}, ::Tuple{Float64, Float64}, ::Vararg{Any})
       @ Plots ~/.julia/dev/Plots/src/axes.jl:301
    [12] get_ticks(sp::Plots.Subplot{Plots.GRBackend}, axis::Plots.Axis; update::Bool, formatter::Function)
       @ Plots ~/.julia/dev/Plots/src/axes.jl:222
    [13] get_ticks(sp::Plots.Subplot{Plots.GRBackend}, axis::Plots.Axis)
       @ Plots ~/.julia/dev/Plots/src/axes.jl:206

With this PR we get again
formatter_new

Furthermore, this PR improves (imho) the combination of log scale and latex formatter

plot(1:10, yscale=:log10, yformatter=:latex)

Before:
formatter_log_latex_old

Now:
formatter_log_latex_new

@codecov
Copy link

codecov bot commented Jan 4, 2023

Codecov Report

Base: 90.65% // Head: 90.79% // Increases project coverage by +0.14% 🎉

Coverage data is based on head (7049aaf) compared to base (3fe21ae).
Patch coverage: 85.71% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4618      +/-   ##
==========================================
+ Coverage   90.65%   90.79%   +0.14%     
==========================================
  Files          41       41              
  Lines        8772     8779       +7     
==========================================
+ Hits         7952     7971      +19     
+ Misses        820      808      -12     
Impacted Files Coverage Δ
src/axes.jl 89.87% <85.71%> (-0.09%) ⬇️
src/backends/gr.jl 91.66% <0.00%> (+<0.01%) ⬆️
src/utils.jl 92.65% <0.00%> (+0.16%) ⬆️
RecipesPipeline/src/utils.jl 97.26% <0.00%> (+1.36%) ⬆️
RecipesPipeline/src/series.jl 93.58% <0.00%> (+2.56%) ⬆️
src/examples.jl 99.20% <0.00%> (+3.17%) ⬆️
RecipesPipeline/src/RecipesPipeline.jl 100.00% <0.00%> (+11.11%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants