Closed rs7q5 closed 1 year ago
You mean like this?
function iplot!!(args...; kwargs...)
viz = ifigure(hold=true)
(length(viz.children) > 0 ? iplot! : iplot)(args...; kwargs...)
end
I think so. If that calls iplot
when a figure does not exist and iplot!
if one does, then yes.
Yes, that's what it does. I'd suggest testing it out for your use case, and if that's what you're looking for, I can add it in into the next release. But you can use this code in the meantime.
It seems it does work, but none of the key words like color or cursor work. The particular error for
iplot!!(xdata,ydata;color=color_opt[idx],cursor=true,ylabel=varTxt)
is
ERROR: LoadError: MethodError: no method matching gl_convert(::String)
Closest candidates are:
gl_convert(::Quaternion) at C:\Users\rs7q5\.julia\packages\GLMakie\lcQNS\src\GLVisualize\visualize\particles.jl:63
gl_convert(::Function, ::Any) at C:\Users\rs7q5\.julia\packages\GLMakie\lcQNS\src\GLAbstraction\GLUniforms.jl:266
gl_convert(::T) where T<:Number at C:\Users\rs7q5\.julia\packages\GLMakie\lcQNS\src\GLAbstraction\GLUniforms.jl:193
I just tried it again today and your code seemed to work. Could this be called outside of a loop so it clears the hold and then still use it? Currently I still have to close the window first to not over plot existing data if I run the for loop again. No big deal, if that's what I need to do, just thought I would ask.
edit: The error seems to actually just be with trying to add y label, but cursor and color does work.
How will the function know whether you want it to clear the hold or not? That is why the iplot
and iplot!
functions are different, so you call one outside the loop and one inside.
That is a good point. I usually do call plot
outside the loop and set some conditions and then use plot!
inside the loop, but iplot
requires you to provide data instead of just axis limits and any other settings, while in plot
you can provide it simply just labels and everything and then add data from the for loop.
iplot!!
and iscatter!!
does avoid the use of having to call one of them outside the loop, but it then does not clear the current figure. If one can initiate an empty iplot
or require particular settings for an empty canvas like you can with plot()
then that would also fix that issue or define it with some settings if necessary for performance. I don't really find having to close the current window manually a huge issue though to your current proposed fix.
To be clear my usual format for adding data a loop is the following
ax = plot(xlabel,ylabel,args...) #any axis or plot args (one can also just call plot())
for x in data
plot!(ax,x,y) #or whatever the data may be and the ax is not actually necessary since it will just add the plot to whatever the current axis/figure is
end
OK, I now understand what you've been asking for!
Will explore providing the similar behavior as plot
and plot!
, with iplot
and iplot!
, to keep the same structure that people are familiar with.
I've updated the title to reflect the essence of what you're asking for, as I understand it.
Yes, that is a better descriptor and would provide the functionality that people are likely more used to. Thank you!
Along the same lines, I forgot to ask. Is there a way in the current implementation to make it so the plot axis/aspect ratio square? passing aspect ratio in or some form of it doesn't seem to do anything.
Yes, I have raised the enhancement request as a separate issue (#16).
With v0.4
, all GLMakie
axis options work with ilines
, iheatmap
, and iscatter
, essentially enabling the functionality suggested in this issue.
I have been using
iscatter!
andiplot!
a lot in for loops and I always have to add an if statement for the first index so I don't get theERROR: No previous canvas available to plot over
error. Would there be a way to try/catch this error to create a canvas using the regular version if the!
errors because of no previous canvas?