Help with graphing table into line graph

조회 수: 3 (최근 30일)
Christopher Kar
Christopher Kar 2023년 11월 28일
답변: Peter Perkins 2023년 11월 28일
Hello,
I am trying to graph a table into a line graph. The table is 4 columns: Outside Diameter(in), Wall Thickness(in), Stress(PSI), and Safety Factor.
I am having trouble formatting the table into a line graph that can show all the values.
The safety factor values are so low that the line is barely visibile to nonexistent.
What would be the proper way to format this? Is there a function for something like this?
Thank you
  댓글 수: 3
Christopher Kar
Christopher Kar 2023년 11월 28일
Ideally, I was looking a single graph/plot that can showcase all 4 columns accurately.
I naturally was drawn to a line graph since it offers good comparisons but I cant figure out a way to format it.
Maybe a bar graph would work better?
I am working on Matlab 9.11.0.1769968 (R2021b)
Dyuman Joshi
Dyuman Joshi 2023년 11월 28일
편집: Dyuman Joshi 2023년 11월 28일
"Ideally, I was looking a single graph/plot that can showcase all 4 columns accurately."
If the scaling of the 4 data-sets are quite different, one option is to use log scales on yaxis. However, this would not work as expected if there is negative or 0 values in the data.
Also, check out stackedplot.

댓글을 달려면 로그인하십시오.

답변 (1개)

Peter Perkins
Peter Perkins 2023년 11월 28일
This spreadsheet is kind of messed up, and I will let you figure out how best to read it in. Given that, it seems like stackedplot would be useful.
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554152/Data.xlsx");
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
t.OD_in_ = [1;1;1;1;1.25;1.25;1.25;1.25;1.5;1.5;1.5;1.5;1.75;1.75;1.75;1.75];
t.WT_in_ = [3/25;5/32;3/16;1/4;3/25;5/32;3/16;1/4;3/25;5/32;3/16;1/4;3/25;5/32;3/16;1/4];
t
t = 16×4 table
OD_in_ WT_in_ x__PSI_ SF ______ _______ _______ _____ 1 0.12 57321 1.343 1 0.15625 49185 1.566 1 0.1875 45075 1.708 1 0.25 40744 1.89 1.25 0.12 34085 2.259 1.25 0.15625 28609 2.691 1.25 0.1875 25736 2.992 1.25 0.25 22469 3.427 1.5 0.12 22539 3.416 1.5 0.15625 18639 4.131 1.5 0.1875 16556 4.651 1.5 0.25 14104 5.459 1.75 0.12 15991 4.815 1.75 0.15625 13084 5.885 1.75 0.1875 11516 6.686 1.75 0.25 9635 7.992
stackedplot(t)
This uses a table. You might also want to look at timetables to plot vs. time, but I actually don't think that's what you are doing. In fact, it seems like you really want a surface plot of x and SF vs. OD and WT. But that's not what you described.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by