InteractiveViz.jl icon indicating copy to clipboard operation
InteractiveViz.jl copied to clipboard

Allow iplot to specify axes limits, labels, etc, without providing data

Open rs7q5 opened this issue 2 years ago • 11 comments

I have been using iscatter! and iplot! a lot in for loops and I always have to add an if statement for the first index so I don't get the ERROR: 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?

rs7q5 avatar Oct 11 '21 00:10 rs7q5

You mean like this?

function iplot!!(args...; kwargs...)
    viz = ifigure(hold=true)
    (length(viz.children) > 0 ? iplot! : iplot)(args...; kwargs...)
end

mchitre avatar Oct 11 '21 01:10 mchitre

I think so. If that calls iplot when a figure does not exist and iplot! if one does, then yes.

rs7q5 avatar Oct 11 '21 19:10 rs7q5

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.

mchitre avatar Oct 12 '21 01:10 mchitre

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

rs7q5 avatar Oct 13 '21 15:10 rs7q5

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.

rs7q5 avatar Oct 14 '21 15:10 rs7q5

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.

mchitre avatar Oct 19 '21 04:10 mchitre

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

rs7q5 avatar Oct 19 '21 15:10 rs7q5

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.

mchitre avatar Oct 19 '21 15:10 mchitre

Yes, that is a better descriptor and would provide the functionality that people are likely more used to. Thank you!

rs7q5 avatar Oct 19 '21 16:10 rs7q5

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.

rs7q5 avatar Nov 01 '21 21:11 rs7q5

Yes, I have raised the enhancement request as a separate issue (#16).

mchitre avatar Nov 03 '21 06:11 mchitre