My issue might be related or even a duplicate of #2889
With one of the latest updates using the pyplot backend Julia, gives the
ERROR: LoadError: MethodError: no method matching getindex(::Int64, ::UnitRange{Int64})
when plotting and saving a plot that contains the xticks property:
using Plots
x = 0:3600:5*86400
y = x
pyplot() # commenting this out makes the code work
plt = plot( x, y, xticks=( 0:86400:5*86400, 0:5))
savefig( plt, "test.png")
The index error arises because the function below expects latexstring to be enclosed by "$" sign:
This should work in your case:
plt = plot(x, y, xticks=( 0:86400:5*86400, ["\$0\$", "\$1\$", "\$2\$", "\$3\$", "\$4\$"]))
@BeastyBlacksmith Should we support passing iterators without elements being enclosed by "$" sign?
I just wanted to note here what I said in #2889. As of Plots.jl 1.5.6, this requirement on tick labels with PyPlot means that the interface is different for different backends. The tick labels work as expected without "\$" delimiters with GR, for example.
@Diaga would you please see if we could first make sure that $$ are present and if they are absent optionally put them in? I thought of this case, but for some reason could failed at this (can't exactly remember why checking for surrounding $ was difficult at that time.
This is only pyplot backend behavior. This was input for reasons mentioned in https://github.com/JuliaPlots/Plots.jl/issues/2889
Everything I did in that PR is a hack, due to matplotlib limitation really.
For future cases, please mention me in any of pyplot issues. I think at this point pyplot backend is what I focused on during the last few months
Perhaps @LakshyaKhatri would be interested in this issue too
@Diaga Thanks for the right way to do it. I have tested your solution and it works.
As far as the question of the "support of passing iterators without elements being enclosed by "$" sign? is concerned, in my humble opinion it would be pretty strange if it worked without any backend or with special backends but with other backends or maybe even only pyplot not.
Should we support passing iterators without elements being enclosed by "$" sign?
I don't know the specifics of the pyplot backend here, but I would expect user to pass LaTeXStrings, if they want computer modern ticklabels and get sans serif numbers if they pass plain numbers (pgfplotsx is an exeption here in that its default font is computer modern, since its actually using LaTeX)
I don't know the specifics of the pyplot backend here, but I would expect user to pass LaTeXStrings, if they want computer modern ticklabels and get sans serif numbers if they pass plain numbers (pgfplotsx is an exeption here in that its default font is computer modern, since its actually using LaTeX)
If would agree that user who prefer computer modern ticklabels would pass LaTeXStrings, but I think that those users who jus pass plain numbers simply don't really care if their ticklabels are sans serif or computer modern or anything else as long as they have the correct values and don't look too ugly.
Sorry, I just want to check since it wasn't commented on at all: Is the fact that the interface for tick labels is different now with the PyPlot backend as compared to all of the others not an issue? I would think that whatever solution is come to, using LaTeXStrings or whatever else, the first step is to make sure the interface is consistent across backends.
The index error arises because the function below expects
latexstringto be enclosed by "$" sign:This should work in your case:
plt = plot(x, y, xticks=( 0:86400:5*86400, ["\$0\$", "\$1\$", "\$2\$", "\$3\$", "\$4\$"]))
This works for single line strings, but strings with "\n" aren't interpreted correctly. For example,
plot(x, y, xticks=( 0:86400:5*86400, ["\$0\n0\$", "\$1\$", "\$2\$", "\$3\$", "\$4\$"]))
yields
