How to scale transparency with node values in graph plot?

12 次查看(过去 30 天)
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 个评论
Christine Tobler
Christine Tobler 2023-4-25
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.

请先登录,再进行评论。

回答(1 个)

Manikanta Aditya
Manikanta Aditya 2023-4-25
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.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by