Is it possible to use gscatter in matlab app designer?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
dpb
2023-10-22
编辑:dpb
2023-10-22
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 个评论
Dyuman Joshi
2023-10-26
Walter Roberson
2023-10-26
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
2023-10-22
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 个评论
Walter Roberson
2023-10-23
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))
dpb
2023-10-23
编辑:dpb
2023-10-24
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!