3D plotting of known data
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
William Rose
2022년 6월 27일
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
William Rose
2022년 7월 4일
@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.
추가 답변 (1개)
Bill Murray
2022년 7월 4일
댓글 수: 1
William Rose
2022년 7월 13일
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1063610/image.jpeg)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!