Is it possible to use gscatter in matlab app designer?
Show older comments
Hi! :)
I am watching some videos of matlab on the internet. In the videos a man is applying just x and y axis plots and I think they dont look that interesting .
Does anybody knows how or whether it is possible to use gscatter plots in matlab app designer. I have matlab 2018b release.
Answers (2)
Works with R2021b; I do not know at what release the support for uiaxes was introduced; used to be able to get to the doc for earlier releases, now I don't see any way to get there any more...nothing was mentioned in R2018b release notes but that doesn't mean too much for small incremental improvement.
Current doc shows the syntax and explicitly mentions ax or uiaxes object handle; if your release doesn't show that, then it won't work and nothing you can do about it other than either upgrade to a release that does support it or generate the scatter plot by groups a group at a time with regular scatter() plot and grouping variables. One could probably get clever and do it in a one-liner with varfun if your data are in a table or certainly with findgroups and splitapply. "More than one way to skin a cat..."
load carsmall
whos
[g,id]=findgroups(Model_Year);
hAx=axes; hold(hAx,'on')
splitapply(@(x,y)scatter(x,y,'filled'),Displacement,Horsepower,g)
legend(hAx,"Model Year "+string(1900+id),'location','northwest')
xlabel('Displacement'), ylabel('Horsepower')
I wasn't able to get varfun() to work with scatter() for some reason...not at all clear why it shouldn't work similarly as does splitapply() above.
7 Comments
Dyuman Joshi
on 22 Oct 2023
"used to be able to get to the doc for earlier releases, now I don't see any way to get there any more"
I think there's a trick to get the documentation of a function corresponding to a release. If I find it, I'll update you here as well.
That's when the uiaxes itself was released; the question here is when the support for uiaxes as the target for gscatter() was introduced (in addition to the default axes) The doc says gscatter (in Stat TB) was introduced prior to R2006a so it predates the introduction of the uiaxes by some 10 releases and so wouldn't have known anything about them initially...but when TMW got around to it is the question.
Dyuman Joshi
on 26 Oct 2023
Okay, got it.
I found a way to get documentation of functions w.r.t a specific MATLAB release -
Current link
R2019b link
Insert /releases/MATLAB_Version/ between /help/ and /Toolbox_Name/function_name
Replace Toolbox_Name with MATLAB for built-in functions.
Walter Roberson
on 26 Oct 2023
R2018a, which was being asked about, did not support passing in an axes.
Actually, OP wrote "I have matlab 2018b release." so could be lucky and it was in between the two.
Do you know of a way to get to the doc for older releases, Walter? I am sure I used to be able to find them, but I can't seem to find any way to do so now; I tried when answering this before...
Dyuman Joshi
on 26 Oct 2023
Walter Roberson
on 26 Oct 2023
Mathworks only keeps the latest 5 years on public-facing sites. We discussed this with them, and they said that it was taking significant resources to keep updating the old documentation to match changes in their search engine.
They had offered to make older releases available as PDFs, but they have not done that.
Walter Roberson
on 22 Oct 2023
0 votes
gcf() and newplot() can only "see" figures and axes that have their HandleVisibility set 'on'
uifigures default to HandleVisibility off -- and in your release, the HandleVisibility cannot be turned on for uifigure() so it is not possible to "fool" gcf into looking for uifigures by turning the handle visibility on.
R2019b is the first release that supported passing an axes handle to gscatter
In your R2018b release what you need to do is allow gscatter to plot into a traditional figure with traditional axes, and then copyobj() the contents into your uiaxes and then delete the traditional figure . This will cause the traditional figure to flash into existence and be drawn into before disappearing again with the contents showing up in the uiaxes.
This was not a great situation, but it is what was available 5 years ago.
3 Comments
"This will cause the traditional figure to flash into existence and be drawn into before disappearing again..."
Could one not set 'Visible','off' to not have that side effect, Walter?
Above I presumed one could use scatter() with a uiaxes handle in R2018b; is that not the case, either? This thing of hiding prior release doc on the web site is a real pain...
Good point about the possibility of turning visbility off.
There are some cases where you must let an axes render before it has correct / consistent information, but I think in this particular case it would not be a problem.
You can use scatter, but it takes more work -- either calling scatter() once for each group or else fudging the legend() entries
gscatter(1:10, rand(10,5), randi(3,1,10))
I'm pretty sure given the limitations I'd prefer the above illustration with @splitapply to do the grouping and plotting directly into the uiaxes over the workaround of plotting to a normal axis and then copyobj(). As the example shows, there's no "fudging of legend entries" required...
That does presume, of course, that scatter and legend had been updated to allow a uiaxes handle by the given release.
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
