corrplot plotting on strange x and y axes values
15 views (last 30 days)
Show older comments
I have a dataset (Metdata, attached) that I want to use corrplot (attached) with.This works but the X axis and Y is much larger for the scatter plots. It seems that it gets stuck on the histogram x and y axes. For example the visibility plots x-axis go over 2000, but visibility values < 500. Is there a way to change the axes values without zooming in independently on each plot?
Matlab version: Matlab R2013a
1 Comment
Ryan
on 8 Feb 2019
I am having the exact same problem. I have a 12 x 12 correlation plot. All of which have data points compressed to the left so that you cannot see any trend at a glance. The data range in some plots only goes up to 500, yet the axis extends to 3000. Did you find a solution to this?
Answers (1)
Adam Danz
on 8 Feb 2019
Edited: Adam Danz
on 8 Feb 2019
Yeah, this is annoying.
You can loop through each scatter plot and set the x and y limits to the x,y ranges within the data. Since the x and y data ranges are the same within rows and within columns, you'll still have identical axis limits within rows and columns. This example uses the "MetData" dataset proivided by the OP.
[~, ~, h] = corrplot(MetData); %grab handle to plot objects
lineHandles = h(strcmp(get(h, 'type'), 'line')); %get handles for scatter plots only
% Loop through each scatter plot
for i = 1:numel(lineHandles)
x = lineHandles(i).XData; %x data
y = lineHandles(i).YData; %y data
xlim(lineHandles(i).Parent, [min(x), max(x)]); % set x limit to range of x data
ylim(lineHandles(i).Parent, [min(y), max(y)]); % set y limit to range of y data
% To convince yourself that the axis scales are still the same within rows/cols,
% include these two lines of code that will display tick marks.
%lineHandles(i).Parent.Position(3:4) = lineHandles(i).Parent.Position(3:4) * .8;
%set(lineHandles(i).Parent, 'XTickMode', 'auto', 'XTickLabelMode', 'auto', 'YTickMode', 'auto', 'YTickLabelMode', 'auto')
end
% now take care of the x axis limits of the histogram plots
histHandles = h(strcmp(get(h, 'type'), 'histogram')); %handles to all hist plots
% loop through hist plots
for j = 1:numel(histHandles)
x = histHandles(j).BinEdges; %bin edges
xlim(histHandles(j).Parent, [min(x), max(x)]); %set x limits
end
Not sure why the last histogram has tiny bins (that's not from my code).
4 Comments
Carlos Borau
on 9 Dec 2021
This worked but at least in my case I needed to tweak manually the x limits to adjust the x labels at the bottom.
In the histHandle loop I added:
curr_fig.Children(nvars*nvars+(nvars+1)).UserData{1}(nvars,j).XLim = histhandles(j).BinLimits;
where
nvars = numel(histHandles)
and
curr_fig = gcf
(be aware, not the handle returned by the corrplot function!). That UserData field stores several axes, some of them repeated. Maybe there is a more elegant way to do it, but I could not find it.
Adam Danz
on 9 Dec 2021
Thanks for your comment, Carlos. Why did you need to adjust the x-axis limits? The histogram bins should have different axis limits than the scatter plots. For example, the x-axis limits for the 4x4 axes in my answer are shown below. Each column of axes contain the same x-axis limits except along the diagonal which contains the histograms (same with the rows of the y-axis limits, not shown). The xlim of historgrams should include the xlim of the scatter axes but they don't have to be the same.
[ 0 510] [0 14.3] [0.7 21.5] [0 3.8]
[1.3 500] [0 14.5] [0.7 21.5] [0 3.8]
[1.3 500] [0 14.3] [0.5 21.5] [0 3.8]
[1.3 500] [0 14.3] [0.7 21.5] [0 3.8]
To see the xlims for your plot,
[~, ~, h] = corrplot(___);
ax = arrayfun(@(h)ancestor(h,'Axes'), h); % axis handles
reshape(get(ax, 'xlim'),size(h)) % xlim array
See Also
Categories
Find more on Data Distribution Plots 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!