필터 지우기
필터 지우기

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