フィルターのクリア

How to change data stacking order for a single series in bubble charts?

3 ビュー (過去 30 日間)
phenan08
phenan08 2023 年 10 月 21 日
コメント済み: Star Strider 2023 年 11 月 1 日
I have a single but large series of xyz data that I want to plot as a bubble chart with bubble colors related to the bubble size values.
However, the plot is not easily readable because the most intense bubbles are hidden by some lower intensity bubbles. How can I change the stacking of the bubbles as a function of bubble size (to plot the most intense bubbles on top of the lowest ones).
Here is a sample code:
figure ;
N = 1e5 ;
x = randn(N,1) ;
y = rand(N,1) ;
z = randi(1e6,[N,1]) ;
[~,edge,idx] = histcounts(z) ;
colors = interp1([min(edge);max(edge)],[1 1 1 ; 0.5 0.5 0.5],edge,"linear","extrap") ;
c = colors(idx,:) ;
figure ;
colormap(c) ;
bubblechart(x,y,z,1:numel(z)) ;
which produces the following output:

採用された回答

Star Strider
Star Strider 2023 年 10 月 21 日
MATLAB plotting functions generally plot in the order specified in the pllotting command, and later objects are plotted ‘on top of’ (for lack of a better description) the objects plotted prior to them. Changing the plotting order could be an option.
Otherwise, setting MarkerEdgeAlpha and MarkerFaceAlpha to change their transparencies could work.
  2 件のコメント
phenan08
phenan08 2023 年 11 月 1 日
Tank you Star Strider.
As there is only one series to plot, there is no way to change the plotting order of the different series.
However, it is possible to sort the series by ascending Z values.
Without sorting, the representation is not very readable:
N = 500 ;
X = rand(N,1) ;
Y = rand(N,1) ;
Z = rand(N,1) ;
bs = [1 30] ;
figure ;
bubblechart(X,Y,Z,sqrt(gray(N)),"MarkerFaceAlpha",1) ;
bubblesize(bs) ;
But once the data are sorted, it is much better.
[Z_sorted,idx_sort] = sort(Z,"ascend") ;
X_sorted = X(idx_sort) ;
Y_sorted = Y(idx_sort) ;
figure ;
bubblechart(X_sorted,Y_sorted,Z_sorted,sqrt(gray(N)),"MarkerFaceAlpha",1) ;
bubblesize(bs) ;
Star Strider
Star Strider 2023 年 11 月 1 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by