3D plotting of known data

I'm trying to plot a 3D graph, which shows time vs bus number vs voltage (pu). The latter has a minimum and maximum value.
The following is an example of the data.
time (1...24hours)
bus number (1....10)
voltage (pu) - bus 1 = 0.93(min), 1.056(max), bus 2 = 0.926(min), 1.063(max), ... up to 10 buses

 Accepted Answer

Generate sample data: ten sinusoidal voltage records, with random variation in amplitude and frequency:
t=0:.5:24;
v=(rand(10,1)-.5).*cos((1+rand(10,1))*t);
Plot the traces as ten 2D records, on one plot:
figure; plot(t,v(1,:),'-ro',t,v(2,:),'-go',t,v(3,:),'-bo') %v1 to v3
hold on;
plot(t,v(4,:),'-rx',t,v(5,:),'-gx',t,v(6,:),'-bx') %v4 to v6
plot(t,v(7,:),'-r+',t,v(8,:),'-g+',t,v(9,:),'-b+',t,v(10,:),'-r*')
legend('Bus 1','Bus 2','Bus 3','Bus 4','Bus 5','Bus 6','Bus 7','Bus 8','Bus 9','Bus 10');
If you want paralell plots that looks three dimensional, you could do
bus=(1:10)'.*ones(size(v)); %create array with the bus numbers
figure; %new figure for plotting
plot3(t,bus(1,:),v(1,:),'-ro',t,bus(2,:),v(2,:),'-go',t,bus(3,:),v(3,:),'-bo') %v1,v2,v3
grid on; hold on;
plot3(t,bus(4,:),v(4,:),'-rx',t,bus(5,:),v(5,:),'-gx',t,bus(6,:),v(6,:),'-bx') %v4,v5,v6
legend('Bus 1','Bus 2','Bus 3','Bus 4','Bus 5','Bus 6'); %add legend
xlabel('Time'); ylabel('Bus'); zlabel('Voltage'); %add axis labels
You can click and drag on the plot above, to rotate it. Obviously, you could add a line of code for v7 to v10. Or you could use a for loop that loops over i=1:10 to do all ten. Try it. Good luck.

11 Comments

Dear William,
Thank you for your valued response. I may have omitted an important part of the information. Please see bus voltage (pu), attached, which is in 2D. As you can see the voltage is subject to the varying load during the day. I'm trying to depict this in 3D exactly as per your second graph. The attached is the information for bus 1 but there are 9 other as previously mentioned.
Regards
I think you can use the code I posted, but instead of using the simulated voltages, v, which I generated for demonstration purposes, use the voltages you have measured, and the common time vector, t, for those voltages. If you want to post a .mat file or a .txt file wth the numbers for all ten voltage measurements over 24 hours, I can show you, but I won't get to it until tonight.
Please see data for all buses in the attached mat file as requested. It is simulated over 24 hours. The original mat file, which is simulated over 86400s is too big.
Thank you for your patience.
[edit: I hit submit before I was done... not the first time...]
data=load('3Dbus1_10');
t=data.Bus1_10.Time;
v=data.Bus1_10.Data;
bus=ones(size(v)).*(1:10); %create array with the bus numbers
colororder=[1,0,0;1,.5,0;1,1,0;.5,1,0;0,1,0;0,1,.5;0,1,1;0,.5,1;0,0,1;1,0,1];
figure; %new figure for plotting
for i=1:10
plot3(t,bus(:,i),v(:,i),'Color',colororder(i,:),'Marker','o')
hold on
legendstr{i}=sprintf('Bus%2d',i);
end
grid on;
legend(legendstr);
xlabel('Time'); ylabel('Bus'); zlabel('Voltage'); %axis labels
Try the above. You can click and drag on the plot to rotate it.
Thank you. Appreciate the quick support.
I do have a final request , which will be the last. It is possible
a) to convert the 3D graph to a surface graph, including a colour legend?
b) to add min and max lines, say 0.95pu and 1.05pu, much like attached pdf illustration?
data=load('3Dbus1_10');
t=data.Bus1_10.Time;
v=data.Bus1_10.Data;
bus=1:10; %bus numbers
figure; %new figure for plotting
surf(bus,t,v,'EdgeColor','none')
hold on
%Next, add semi-transparent limit surfaces
%FaceAlpha sets transparency level
surf(bus,t,1.05*ones(size(v)),'FaceColor','r','EdgeColor','none','FaceAlpha',.3)
surf(bus,t,0.95*ones(size(v)),'FaceColor','b','EdgeColor','none','FaceAlpha',.3)
grid on; colorbar
xlabel('Bus'); ylabel('Time (h)'); zlabel('Voltage (pu)'); %axis labels
Try that. In Matlab, you will be able to click and drag in the plot to rotate it in 3D. This will allow you to examine it from underneath, to see possible violations of the lower limit.
Thank you. Amazing speed of service and excellent feedback.
@Bill Murray, you're welocome. Thank you for your kind comments. If my answer suffices, please accept it.
Almost all of us on this site are volunteers who come on to improve their Matlab skills and share ideas. I was only asking questions at first, and now I am doing more answering. I assume those who have "Staff" after their user name are not volunteers.
I ran the script successfully once but received below error message after a few attemps.
Error using load
Unable to find file or directory '3Dbus1_10'.
The image (saved as emf) when inserting into Word document is completely distorted.
I managed to resolve the problem.
The only concern is the image resolution when inserting the saved imaged in Word.
@Bill Murray, thnk you for accepting the answer. I am not sure how to improve the image resolution in word. Of course there are many ways to import into word nd they offer different potential resolutions.
Once you have created the figure, you can click File -> Save As. Window pops up, and a the bottom there is a "Save as file type" option, with 14 possible file formats to save as. I am sure that some of those formats will import well into word. I usually use jpg and it looks good to me wen I import to Word for a manuscript submission.
Another method is to make the figure as large as possible on screen, then taking a screen shot, which you can save as jpg or png or various other formats, depending on your screenshot app. Then you import the sceenshot.

Sign in to comment.

More Answers (1)

Bill Murray
Bill Murray on 4 Jul 2022
Thanks for the response. The best resolution is enhanced metafile (emf) but as I said the image is completely distorted.
Please advise how I change the bus identification numbers from 1-10 eg 701,711,741,750,etc

1 Comment

I am sorry to hear that theimage is completely distorted. I have had good luck with the screen capure program SnagIt. I bought a personal copy over 5 years ago, never upgraded, and it still works. I can capture a plot that is on my screen and save it in any number of formats. It also comes with an image editing program, with a lot of capabilities, that lets me touch up an image. Usually I save as jpeg. Then I import the image into Word when I compose a manuscript.
To change the bus labels from (1 to 10) to a set of arbitrary numbers, append the following commands to the code I posted earlier:
xlim([1,10]); %axis limits=[1,10] instead of the default [0,10]
xticks(bus); %make ticks at 1,2,3,...,10
xticklabels({'701','711','741','750','752','757','767','777','787','799'});
The produces the plot below. By the way, I saved this plot as a jpeg file with the SnagIt program, so that I could upload it to this answer box.

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!