2D scatter plot with custom glossy ball markers

バージョン 1.0.1 (47.6 KB) 作成者: Cyril
Introduces the function ballscatter(x,y) to generate a 2d scatter plot of x,y arrays with markers looking like glossy 3d balls.
ダウンロード: 14
更新 2025/3/14

ライセンスの表示

Introduces the function ballscatter(x,y) to generate a 2D scatter plot of x,y arrays with markers looking like glossy 3D balls instead of the usual disks. The ball markers are emulated by a series of superimposed disk markers generated with the built-in plot() function with colors, radii and centers changed gradually to reproduce a bright spotlight on the upper left part of the main disk.
The first optional argument is the markerSize corresponding to the marker area in number of pixel squared. The marker color is provided as a second optional argument (RGB triplet) or as a keyword-argument with key 'MarkerFaceColor' and value corresponding to either a RGB triplet (e.g. [0,0,1] for blue) or a string 'blue' for standard MATLAB colors.
Caveat: the generated ball markers are not stable under zooming or rescaling of the plot figure. Therefore, the figure size should be set beforehand and not changed after generating the ballscatter plot. This could be fixed in a future version using callbacks and the 'SizeChangedFcn' property of the figure. This ballmarker scatterplot works okay with log scales, provided it is set beforehand with set(gca, 'XScale', 'log') and/or set(gca, 'YScale','log'). A later change of axis scaling after ballscatter() has been executed would result in distorted markers.
By default, when displaying legends, the icon associated to a ballscatter won't show the correct custom marker as the icon, only a flat disk with the same color. To fix the legend appearance, you can run the fix_ballscatter_legend() function provided along with the main code. The demo folder contains an example code.
Example:
x = linspace(2,100,10);
y = x.^3;
figure
set(gcf, 'Position', [600, 400, 800, 400])
%set(gca, 'XScale','log')
%set(gca, 'YScale','log')
%ballscatter(x,y); %minimal syntax
%ballscatter(x,y,200); %specify markerSize
%ballscatter(x,y,200,[0,128,128]/255); %specify markerSize and color as RGB triplet
ballscatter(x,y,200,'MarkerFaceColor', 'red'); %other way to specify color, either as a RGB triplet or colorname

引用

Cyril (2025). 2D scatter plot with custom glossy ball markers (https://jp.mathworks.com/matlabcentral/fileexchange/179319-2d-scatter-plot-with-custom-glossy-ball-markers), MATLAB Central File Exchange. に取得済み.

MATLAB リリースの互換性
作成: R2024b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.0.1

-Update code to fix the legend entry appearance and some minor bugs

1.0.0