Wrong axis value in correlation plot
Mostra commenti meno recenti
Hi, I used correlation plot(corrplot) and getting the following graph. And it is obvious the var2 is bounded by -1 from the two scatter plot and as well as from the data. But the second histogram starts from a starting value much smaller value. I'm not sure is it a bug or my setting problem. Actually I did not do any settings, this is the default output from corrplot.

2 Commenti
the cyclist
il 13 Lug 2019
Can you upload your data and code? This would make your problem easier to diagnose.
JT Yang
il 13 Lug 2019
Risposta accettata
Più risposte (2)
It's a confusing labeling problem -- the ticks aren't actually the variables on the plot for the histogram but for the scatter plots -- the axes values are for the scatter plot in the upper right quadrant which is scatter(x(:,2),x(:,1)) while the lower left is scatter(x(:,1),x(:,2)).
So, the x-axes limits are for var2 which are bounded at -1; the labels have nothing to do with the histograms; only the scatter plots. TMW just placed the x-axis labels for all the suplots at the bottom instead of keeping them with their respective suplot locations.
If create a poor-man's copy...
subplot(2,2,1)
hist(MCMC(:,1),100)
subplot(2,2,2)
scatter(MCMC(:,2),MCMC(:,1))
ylim([0 0.025])
xlim([-1.105 -0.7])
subplot(2,2,3)
scatter(MCMC(:,1),MCMC(:,2))
xlim([0 0.025])
ylim([-1.105 -0.7])
subplot(2,2,4)
hist(MCMC(:,2),100)
xlim([-1.05 -0.75])
one gets

so, while perhaps confusing, looks like the data are in fact correct...I don't have the Econometrics TB so can't go in and query what the actual limits are on each subplot() but doing so will make things clear, I expect. I fiddled around to roughly approximate the appearance on the LRH one...that took some doing...what the logic is that created the actual limits would be interesting to go look at, perhaps.
8 Commenti
As Cyclist says, this is a quality of implementation problem if not an outright bug so is worthy of submitting a service request on.
I presume they didn't do anything more exotic that create a bunch of specialized subplot() with position adjusted and axes hidden...as suggested earlier, if you'll get the axes handles from the figure created, you can directly query the xlim property for each subplot() and determine precisely what those values are.
Or, if it is an m-file, you could go read the source and try to decipher how they did set the x-limit property for each.
That would make it absolutely clear whether my supposition is, in fact, correct (altho I'm quite confident it is, there's always a chance there's a more significant bug)
dpb
il 14 Lug 2019
Save the .fig file and attach it. Even w/o the TB, should be able to open the .fig file and poke around inside...
JT Yang
il 14 Lug 2019
Wowsers!!! They went all out...
>> openfig('corrplot.fig')
Warning: Unable to load instances of class matlab.ui.controls.AxesToolbar into a heterogeneous array. The definition of
...
ans =
Figure (2) with properties:
Number: 2
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [675 549 570 420]
Units: 'pixels'
Show all properties
>> hF=gcf;
>> hA=hF.Children
hA =
7×1 Axes array:
Axes (PlotMatrixHistAx)
Axes (PlotMatrixHistAx)
Axes (PlotMatrixScatterAx)
Axes (PlotMatrixScatterAx)
Axes (PlotMatrixScatterAx)
Axes (PlotMatrixScatterAx)
Axes (CorrPlot)
>> xl=get(hA,'XLim');
>> xl{:}
ans =
0.0032 0.0280
ans =
-1.0300 -0.7700
ans =
0.0051 0.0261
ans =
-1.1193 -0.7334
ans =
0.0051 0.0261
ans =
-1.1193 -0.7334
ans =
0 1
>>
Looks like they created an axes for each quadrant for starters and plotted scatter and then overlaid two additional axes for the two histograms on top...instead of just a simple four-axes subplot() thing.
But, you can see where they left the ranges after done by default...
I confirmed that axes 2 and 6 are the LRH corner by
text(hA(6),-1,-0.8,'SIX')
text(hA(2),-1,7000,'TWO')
hA(6).Color='none';
hA(2).Color='none';
which also reveals they drew a line on the scatter axes that seems to traverse the range of the scatter plot data--I don't understand the purpose for it to then hide it...
Curiouser and curiouser... :)
ADDENDUM:
It appears the line is plot() of the scatter data sorted by increasing x...for what purpose still escapes me--they could have easily found the ranges by simply using min()/max() unless were too lazy and letting the autoranger default the axis limits--but even that could be just the two extrema; why duplicate the whole data set yet again??? But no, that isn't it because the limits aren't even as would otherwise be and
>> hA(6).XLimMode
ans =
'manual'
>>
confirms that.
Bizarre.
JT Yang
il 14 Lug 2019
dpb
il 15 Lug 2019
One additional note: The line for the diagonal axes that isn't shown is just the variable plotted against itself--the 'ii' case so it is simply a 45-degree line of the range of the variable. The just didn't bother to fix up the logic to not plot the i==j case but did all and then overwrote the diagonal with the histograms not bothering to delete() the extra axes/line.
Amin Salehi
il 7 Dic 2023
Modificato: Amin Salehi
il 7 Dic 2023
0 voti
Yup, I see the same bug (different dataset) the histogram x-axis are wrong.
Categorie
Scopri di più su Data Distribution Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
