Legend in multiple plots: example bubblecharts or combined plot bubblechart and scatter
Hi, I am trying to display to variables on a map and add a legend for both of the variables. Since I the problems is the legend I removed the map behind the plot to just focus on the variables.
I splitted the two variables first in two seperate plots to show how the legend should look like for each variable. Than I combine it in two ways and discuss the legend problems that I have face.
% create random data
xCoordinate = randi([3.1976e+05 8.2960e+05],21, 1); %Location on a map xCoordinate
yCoordinate = randi([6.1639e+06 7.2924e+06],21, 1); %Location on a map yCoordinate
markerSizesV = randi([0 5],21, 1);
markerSizesC = randi([1 379],21, 1);
%% create bubblechart Cats per km^2 of region with legend
bC = bubblechart(xCoordinate,yCoordinate,markerSizesC, [1, 1, 1]); %FaceColor white
bC.MarkerEdgeColor = [0,0,0]; %EdgeColor black
bubblesize([4 15]) % limit the bubblesize
axis equal % ensures 1 unit in x equals 1 unit in y
axis off % romoves the axis
blgdC1 = bubblelegend({‘Cats’;’per km^2′},’Location’,’eastoutside’); % plots the legend
The legend for Cats per km^2 should look like in the plot above. (Ignor the that some of the bubbles are getting cut off this doesn’t happens when the map is ploted as well.)
%% create bubblechart Cat visits per region with legend
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
blgdV1 = bubblelegend({‘Cat Visits’;’per region’});
The legend for Cat visits per region should look like in the plot above. (Ignor the that some of the bubbles are getting cut off this doesn’t happens when the map is ploted as well.)
%% combined bubblechart Cats per km^2 and Cat visits per region
bC = bubblechart(xCoordinate,yCoordinate,markerSizesC, [1, 1, 1]);
hold on
bC.MarkerEdgeColor = [0,0,0];
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
blgdC2 = bubblelegend({‘Cats’;’per km^2′},’Location’,’eastoutside’); %
blgdV2 = bubblelegend({‘Cat Visits’;’per region’},’Location’,’westoutside’);
legend(‘Cats per km^2’, ‘Cat Visits per Region’) %test what legend does
hold off
As soon as I combine two bubblecharts MATLAB combines valus in ratio to each other and combines it also into the same population legend. This is fine if I would have two variables with the same unit / content but different regions.
Therefore I tryed a version with
%% combine bubblechart Cat visits per region with scatter Cats per km^2
s = scatter(xCoordinate,yCoordinate,markerSizesC/2, MarkerFaceColor = "white", MarkerEdgeColor = "#36454F");
hold on
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
blgdV = bubblelegend({‘Cat Visits’;’per region’},’Location’,’westoutside’);
legend(‘Cats per km^2’, ‘Cat Visits per Region’)
hold off
This solves at least the problem that MATLAB considers these two variables should be in relation to each other. Plus the legend for "Cat visits per region" is correct and with the right color and right size.
However I don’t get a legend like this next to my plot as in the bubblechart combinded with scatter.
Is their anyone knowing how to solve this issue with legends?
Thanks for any input in this matter.Hi, I am trying to display to variables on a map and add a legend for both of the variables. Since I the problems is the legend I removed the map behind the plot to just focus on the variables.
I splitted the two variables first in two seperate plots to show how the legend should look like for each variable. Than I combine it in two ways and discuss the legend problems that I have face.
% create random data
xCoordinate = randi([3.1976e+05 8.2960e+05],21, 1); %Location on a map xCoordinate
yCoordinate = randi([6.1639e+06 7.2924e+06],21, 1); %Location on a map yCoordinate
markerSizesV = randi([0 5],21, 1);
markerSizesC = randi([1 379],21, 1);
%% create bubblechart Cats per km^2 of region with legend
bC = bubblechart(xCoordinate,yCoordinate,markerSizesC, [1, 1, 1]); %FaceColor white
bC.MarkerEdgeColor = [0,0,0]; %EdgeColor black
bubblesize([4 15]) % limit the bubblesize
axis equal % ensures 1 unit in x equals 1 unit in y
axis off % romoves the axis
blgdC1 = bubblelegend({‘Cats’;’per km^2′},’Location’,’eastoutside’); % plots the legend
The legend for Cats per km^2 should look like in the plot above. (Ignor the that some of the bubbles are getting cut off this doesn’t happens when the map is ploted as well.)
%% create bubblechart Cat visits per region with legend
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
blgdV1 = bubblelegend({‘Cat Visits’;’per region’});
The legend for Cat visits per region should look like in the plot above. (Ignor the that some of the bubbles are getting cut off this doesn’t happens when the map is ploted as well.)
%% combined bubblechart Cats per km^2 and Cat visits per region
bC = bubblechart(xCoordinate,yCoordinate,markerSizesC, [1, 1, 1]);
hold on
bC.MarkerEdgeColor = [0,0,0];
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
blgdC2 = bubblelegend({‘Cats’;’per km^2′},’Location’,’eastoutside’); %
blgdV2 = bubblelegend({‘Cat Visits’;’per region’},’Location’,’westoutside’);
legend(‘Cats per km^2’, ‘Cat Visits per Region’) %test what legend does
hold off
As soon as I combine two bubblecharts MATLAB combines valus in ratio to each other and combines it also into the same population legend. This is fine if I would have two variables with the same unit / content but different regions.
Therefore I tryed a version with
%% combine bubblechart Cat visits per region with scatter Cats per km^2
s = scatter(xCoordinate,yCoordinate,markerSizesC/2, MarkerFaceColor = "white", MarkerEdgeColor = "#36454F");
hold on
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
blgdV = bubblelegend({‘Cat Visits’;’per region’},’Location’,’westoutside’);
legend(‘Cats per km^2’, ‘Cat Visits per Region’)
hold off
This solves at least the problem that MATLAB considers these two variables should be in relation to each other. Plus the legend for "Cat visits per region" is correct and with the right color and right size.
However I don’t get a legend like this next to my plot as in the bubblechart combinded with scatter.
Is their anyone knowing how to solve this issue with legends?
Thanks for any input in this matter. Hi, I am trying to display to variables on a map and add a legend for both of the variables. Since I the problems is the legend I removed the map behind the plot to just focus on the variables.
I splitted the two variables first in two seperate plots to show how the legend should look like for each variable. Than I combine it in two ways and discuss the legend problems that I have face.
% create random data
xCoordinate = randi([3.1976e+05 8.2960e+05],21, 1); %Location on a map xCoordinate
yCoordinate = randi([6.1639e+06 7.2924e+06],21, 1); %Location on a map yCoordinate
markerSizesV = randi([0 5],21, 1);
markerSizesC = randi([1 379],21, 1);
%% create bubblechart Cats per km^2 of region with legend
bC = bubblechart(xCoordinate,yCoordinate,markerSizesC, [1, 1, 1]); %FaceColor white
bC.MarkerEdgeColor = [0,0,0]; %EdgeColor black
bubblesize([4 15]) % limit the bubblesize
axis equal % ensures 1 unit in x equals 1 unit in y
axis off % romoves the axis
blgdC1 = bubblelegend({‘Cats’;’per km^2′},’Location’,’eastoutside’); % plots the legend
The legend for Cats per km^2 should look like in the plot above. (Ignor the that some of the bubbles are getting cut off this doesn’t happens when the map is ploted as well.)
%% create bubblechart Cat visits per region with legend
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
blgdV1 = bubblelegend({‘Cat Visits’;’per region’});
The legend for Cat visits per region should look like in the plot above. (Ignor the that some of the bubbles are getting cut off this doesn’t happens when the map is ploted as well.)
%% combined bubblechart Cats per km^2 and Cat visits per region
bC = bubblechart(xCoordinate,yCoordinate,markerSizesC, [1, 1, 1]);
hold on
bC.MarkerEdgeColor = [0,0,0];
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
blgdC2 = bubblelegend({‘Cats’;’per km^2′},’Location’,’eastoutside’); %
blgdV2 = bubblelegend({‘Cat Visits’;’per region’},’Location’,’westoutside’);
legend(‘Cats per km^2’, ‘Cat Visits per Region’) %test what legend does
hold off
As soon as I combine two bubblecharts MATLAB combines valus in ratio to each other and combines it also into the same population legend. This is fine if I would have two variables with the same unit / content but different regions.
Therefore I tryed a version with
%% combine bubblechart Cat visits per region with scatter Cats per km^2
s = scatter(xCoordinate,yCoordinate,markerSizesC/2, MarkerFaceColor = "white", MarkerEdgeColor = "#36454F");
hold on
bV = bubblechart(xCoordinate,yCoordinate,markerSizesV, [0.9290, 0.6940, 0.1250]);
bubblesize([4 15])
axis equal % ensures 1 unit in x equals 1 unit in y
axis off
blgdV = bubblelegend({‘Cat Visits’;’per region’},’Location’,’westoutside’);
legend(‘Cats per km^2’, ‘Cat Visits per Region’)
hold off
This solves at least the problem that MATLAB considers these two variables should be in relation to each other. Plus the legend for "Cat visits per region" is correct and with the right color and right size.
However I don’t get a legend like this next to my plot as in the bubblechart combinded with scatter.
Is their anyone knowing how to solve this issue with legends?
Thanks for any input in this matter. legend, multiple, bubblechart, scatter plot MATLAB Answers — New Questions