Scatterplot: Legend does not match color of plots
2 views (last 30 days)
Show older comments
Hello!
I'm trying to plot correlation data onto 10 separate figures, and that works and the colors are coming out the way I want them too but I can't get the colors in the legend to match up with the color of the plots. The inputs for this code are correlation coefficient matrices. I have attached 3 of those below as mat files, and you can input them into this function. I've been trying to look this problem up but none of the solutions are quite working out for me. Any help will be appreciated. Thanks!!
function [] = plotcorr1(varargin)
% Compute number of neurons that we will compare
N = size(varargin{1}, 1);
% Compute number of matrices that we will be utilizing
K = numel(varargin);
% Initialize a cell array with space for N matrices (for N graphs)
C = cell(1, N);
% Make a matrix in each cell of size Nx1
for i = 1:N
C{i} = zeros(N, K);
end
% Put the values into the cell array
% Each cell in C represents the correlations between each neuron with neuron 1, 2, 3....
for j = 1:N
for i = 1:K
C{j}(:, i) = varargin{i}(:, j);
end
end
% Plot!
for j = 1:N
figure(j)
hold on;
for i = 1:K
x = linspace(1, N, N);
y = C{j}(:, i)';
scatter(x, y, 'o', 'filled')
legendInfo{i} = ['Matrix' num2str(i)];
legend(legendInfo);
axis([0 N+1 -.05 .2]);
title(['Correlation between Neuron ' num2str(j) ' and Other Neurons']);
xlabel('Neuron N');
ylabel('Correlation');
end
end
end
0 Comments
Answers (1)
the cyclist
on 23 Jun 2016
I did not look at your code in detail, but I speculate that you are seeing the bug mentioned in this answer.
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!