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

3 次查看(过去 30 天)
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) ;

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by