Is it possible to use gscatter in matlab app designer?

13 visualizzazioni (ultimi 30 giorni)
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.

Risposte (2)

dpb
dpb il 22 Ott 2023
Modificato: dpb il 22 Ott 2023
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
Name Size Bytes Class Attributes Acceleration 100x1 800 double Cylinders 100x1 800 double Displacement 100x1 800 double Horsepower 100x1 800 double MPG 100x1 800 double Mfg 100x13 2600 char Model 100x33 6600 char Model_Year 100x1 800 double Origin 100x7 1400 char Weight 100x1 800 double cmdout 1x33 66 char
[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 Commenti
Walter Roberson
Walter Roberson il 26 Ott 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.

Accedi per commentare.


Walter Roberson
Walter Roberson il 22 Ott 2023
In your release, R2018a, gscatter hard-codes calls to gcf and to newplot without any parameters.
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 Commenti
Walter Roberson
Walter Roberson il 23 Ott 2023
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
dpb il 23 Ott 2023
Modificato: dpb il 24 Ott 2023
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.

Accedi per commentare.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by