How do I specify the size of the markers created by the SCATTER plot in units proportional to the data being plotted in MATLAB 7.6 (R2008a)?
36 次查看(过去 30 天)
显示 更早的评论
I am using the SCATTER function to create a scatter plot of my data using the following syntax,
scatter(X,Y,S)
I would like to specify the marker width as 5 units on the X axis.
采纳的回答
MathWorks Support Team
2013-10-18
The SCATTER function expects its 'S' parameter to contain the marker area in points squared. This area corresponds to the area of a square bounding box around the marker. To make the size of the marker relative to the units of 'X' and 'Y' you will need to convert the marker width in 'normalized' units into 'point' units.
To achieve this, you can first create the scatter plot using the default marker size. You can then determine the ratio of conversion between normalized units and points given the size of the newly created axes, and finally change the "SizeData" property of the scatter plot to the appropriate value.
x = 1:50;
y = rand(1,50);
s = 5; %Marker width in units of X
h = scatter(x,y); % Create a scatter plot and return a handle to the 'hggroup' object
%Obtain the axes size (in axpos) in Points
currentunits = get(gca,'Units');
set(gca, 'Units', 'Points');
axpos = get(gca,'Position');
set(gca, 'Units', currentunits);
markerWidth = s/diff(xlim)*axpos(3); % Calculate Marker width in points
set(h, 'SizeData', markerWidth^2)
The above code uses the "Position" property of the axis to determine the size of the axis in points and the "XLim" and "YLim" properties to determine the size of the axis in normalized units. For more information on the Position, Units and other axes properties, please consult the documentation for AXES properties.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!