Filter löschen
Filter löschen

How to scale transparency with node values in graph plot?

5 Ansichten (letzte 30 Tage)
Amanda Volk
Amanda Volk am 12 Apr. 2023
Kommentiert: Christine Tobler am 25 Apr. 2023
I have generated a 3D graph plot with "usegravity". I am looking for a way to generate this plot as it is "growing" when adding more nodes. I can't do this by replotting in a loop indexing through my data because with "usegravity" (as I understand it) the orientation keeps changing based on which area of the plot is taking up the most space. So instead, I want to scale the transparency of the plot with my node values- does anyone know a good way to do this? Or a way to plot the plot in this 3d usegravity format withou the orientation changing as I add nodes?
Thank you!
  1 Kommentar
Christine Tobler
Christine Tobler am 25 Apr. 2023
Hi Amanda,
For graph plots growing over time, it's often a good idea to generate a plot based on all nodes that there are in the end, and then to use the XData, YData, ZData of that plot to generate previous plots using only a subset of the nodes.
Is this what you are currently doing? I'm not quite sure what the issue with the orientation is... is this about the direction in which we are looking at the 3D axes?
If you want to instead just make one plot of your final graph, and then turn some nodes "off", you can use
highlight(p, 1, Marker='none')
to remove the marker of the first node, for example. But you would still need additional code here to also remove the node label, and probably you would want to remove all edges connecting to this node, too, meaning this can be quite tedious to do. I think you might be better off using the first approach of plotting the smaller graph, and then resetting the nodes by indexing into XData, YData, ZData of the final graph.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Manikanta Aditya
Manikanta Aditya am 25 Apr. 2023
Hi Amanda,
As per my understanding, you are interested to know how to scale the transparency of the plot with node values.
You can use ‘alpha’ property of the plot to set the transparency values based on your node values.
Here is an example showing how you can do it:
% Generate some random 3D data
x = randn(100,1);
y = randn(100,1);
z = randn(100,1);
values = rand(100,1); % Node values to use for setting transparency
% Create the initial plot
figure;
h = scatter3(x,y,z,[],values,'filled');
axis([-3 3 -3 3 -3 3]);
view(3);
set(gca,'Box','on');
% Loop over some more data to add to the plot
for ii = 1:50
% Generate some more random data
x_new = randn(10,1);
y_new = randn(10,1);
z_new = randn(10,1);
values_new = rand(10,1);
% Add the new data to the existing plot
x = [x; x_new];
y = [y; y_new];
z = [z; z_new];
values = [values; values_new];
set(h,'XData',x,'YData',y,'ZData',z,'CData',values);
% Update the transparency based on the node values
alpha_values = values/max(values); % Scale values to range [0,1]
set(h,'AlphaData',alpha_values);
% Pause to show the updates
pause(0.1);
end
Please refer to the following documentation for more info on:
I hope this resolves the issue you were facing.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by