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!