I have a series recipe that formats the x-axis ticks. When I add a vline, the formatting is reset to the default, i.e. my custom formatting disappears.
Is it possible for vline to respect and preserve the formatting of the xticks that already exists?
And, more generally, why is xformatter an attribute of the series and not of the subplot or the axis?
Here is an example code to demonstrate this:
@recipe function _myseries(::Type{Val{:myseries}}, x, y, z)
xformatter --> function (d)
yr = floor(Int, d)
qr = 1 + floor(Int, 4 * (d - yr))
return "$(yr)Q$(qr)"
end
seriestype := :path
end
dates = collect(2021:0.25:2024-0.1)
yvals = rand(length(dates))
plt = plot(dates, yvals, label="y", seriestype=:myseries)
If I add the vline, I get this:
vline!(plt, [2022.5], label="2022Q3", lc=:black)
I can fix the formatting by forcing the xformatter like this:
plt = plot(dates, yvals, label="y", seriestype=:myseries)
vline!(plt, [2022.5], label="2022Q3", lc=:black, xformatter=plt.series_list[1][:xformatter])
I am developing a library, so I don’t want my users to have to do this.
Thanks,
Boyan