CVS yy-axis plot
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Hello,
I have attached the simulation result and csv file but I want to plot these graphs in matlab after plotting the graps in matlab my Y-axis is missing. This is my code I need help please where i went wrong.
plotData = importdata('nmosesd.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
hLine(1)=plot(plotData.data(:,1),plotData.data(:,2),'*-r','LineWidth',2)
hLine(2)=plot(plotData.data(:,3),plotData.data(:,4),'p-b','LineWidth',2)
hLine(3)=plot(plotData.data(:,5),plotData.data(:,6),'o-k','LineWidth',2)
hLine(4)=plot(plotData.data(:,7),plotData.data(:,8),'^-g','LineWidth',2)
title('Output Voltage at 10K\Omega')
set(gca,'FontSize',11);
xlabel('Time','FontSize',11,'FontWeight','bold')
ylabel('Voltage','FontSize',11,'FontWeight','bold')
legend([hLine(1) hLine(2) hLine(3) hLine(4)],'Input Power for Low Vth transistor','Current','Input Power for High Vth transistor', 'Input Power for Standard Vth transistor')
採用された回答
Star Strider
2019 年 5 月 2 日
Try this:
plotData = importdata('nmosesd.csv')
plotData.colheaders(1)
plotData.data(1)
figure(1)
clf
hold on
grid minor
hLine(1)=plot(plotData.data(:,1),plotData.data(:,2),'*-r','LineWidth',2)
hLine(2)=plot(plotData.data(:,3),plotData.data(:,4),'p-b','LineWidth',2)
hLine(3)=plot(plotData.data(:,5),plotData.data(:,6),'o-k','LineWidth',2)
hLine(4)=plot(plotData.data(:,7),plotData.data(:,8),'^-g','LineWidth',2)
hold off
yyaxis right % Add Right Y-Axis
yt = get(gca, 'YTick'); % Get Default Y-Yick Values
newyt = linspace(min(yt), max(yt), 12); % Create New Right Y-Tick Values
newytl = linspace(-100, 1000, numel(newyt)); % Create New Right Y-Tick Labels
set(gca, 'YTick',newyt, 'YTickLabel',newytl); % Set New Right Y-Tick Labels
title('Output Voltage at 10K\Omega')
set(gca,'FontSize',11);
xlabel('Time','FontSize',11,'FontWeight','bold')
ylabel('Voltage','FontSize',11,'FontWeight','bold')
I do not have your data to work with. This works on my test plot.
13 件のコメント
Thank you for yourr answer. but it was not working for me both x and y axis got blank and there is one error :
Undefined function or variable 'yyaxis'.
Error in nmos (line 13)
yyaxis right % Add Right Y-Axis
My matlab edition is R2015a: I also attached my csv file.
Star Strider
2019 年 5 月 2 日
My pleasure.
The yyaxis function appeared first in R2016a.
To use plotyy, you would do something like this:
x = 1:10;
y1 = 2*exp(-0.4*x);
y2 = 2*exp(-0.5*x);
y3 = 2*exp(-0.6*x);
y4 = 2*exp(-0.7*x);
figure
[Ax,H1,H2] = plotyy(x, y1, x, y2);
hold on
plot(x, y3, x, y4)
hold off
yt = get(Ax(2), 'YTick'); % Get Default Y-Yick Values
newyt = linspace(min(yt), max(yt), 12); % Create New Right Y-Tick Values
newytl = linspace(-100, 1000, numel(newyt)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newyt, 'YTickLabel',newytl); % Set New Right Y-Tick Labels
I am not certain the plotyy would work with your code as you posted it, so I will let you adapt your data to this code.
Rai
2019 年 5 月 2 日
The code which you write where I have to make changes? I try to make same changes in the exponential but still not geeting any success
Star Strider
2019 年 5 月 2 日
Plot them as:
figure
[Ax,H1,H2] = plotyy(plotData.data(:,1),plotData.data(:,2), plotData.data(:,3),plotData.data(:,4));
hold on
plot(plotData.data(:,5),plotData.data(:,6), 'o-k', plotData.data(:,7),plotData.data(:,8),'^-g')
hold off
H1.LineStyle = '*-r';
H2.LineStyle = 'p-b';
hold off
yt = get(Ax(2), 'YTick'); % Get Default Y-Yick Values
newyt = linspace(min(yt), max(yt), 12); % Create New Right Y-Tick Values
newytl = linspace(-100, 1000, numel(newyt)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newyt, 'YTickLabel',newytl); % Set New Right Y-Tick Labels
That should work. (I cannot test it because I do not have your data.)
Rai
2019 年 5 月 3 日
After I write your code still the YY-axis current label is missing and x-axis points are not correct. I also try to make legend but it genrate some error. I also attach my CSV data file please check

Star Strider
2019 年 5 月 3 日
Try this:
[plotData,S] = xlsread('nmosesd.csv');
figure
[Ax,H1,H2] = plotyy(plotData(:,1),plotData(:,2), plotData(:,3),plotData(:,4));
hold on
plot(plotData(:,5),plotData(:,6), 'o-k', plotData(:,7),plotData(:,8),'^-g')
hold off
H1.LineStyle = '-.';
H2.LineStyle = '--';
hold off
ylabel(Ax(1), 'V(V)')
ylabel(Ax(2), 'I(mA)');
legend('Low Vth', 'Current', 'High Vth', 'Standard Vth') % Create Legend
ytr = get(Ax(2), 'YTick'); % Get Default Right Y-Yick Values
newytr = linspace(min(ytr), max(ytr), 12); % Create New Right Y-Tick Values
newytrl = linspace(-100, 1000, numel(newytr)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newytr, 'YTickLabel',newytrl); % Set New Right Y-Tick Labels
ytl = get(Ax(1), 'YTick'); % Get Default Left Y-Yick Values
newytl = linspace(min(ytl), max(ytl), 12); % Create New Left Y-Tick Values
newytll = round(newytl,1); % Create New Left Y-Tick Labels
set(Ax(1), 'YTick',newytl, 'YTickLabel',newytll); % Set New Left Y-Tick Labels
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',xt*1E+6)
xlabel('Time (ns)')
producing:

Thank you for help I am geeting the desired graph.. But there is one problem I have to add markes for the other two graphs but it will generate error when ever I try to do it. Also is there any way i make my graphs LineWidth more than this. I use some commands but it will generate errors. I want to my graphs look like this: Please tell me where is problem in code
[plotData,S] = xlsread('nmosesd.csv');
figure
[Ax,H1,H2] = plotyy(plotData(:,7),plotData(:,8), plotData(:,3),plotData(:,4));
hold on
grid minor
plot(plotData(:,5),plotData(:,6), 'o-k', plotData(:,1),plotData(:,2),'^-g')
hold off
H1.LineStyle = '-';
H2.LineStyle = '--';
hold off
ylabel(Ax(1), 'V(V)')
ylabel(Ax(2), 'I(mA)');
legend('Low Vth', 'Current', 'High Vth', 'Standard Vth') % Create Legend
ytr = get(Ax(2), 'YTick'); % Get Default Right Y-Yick Values
newytr = linspace(min(ytr), max(ytr), 12); % Create New Right Y-Tick Values
newytrl = linspace(-100, 1000, numel(newytr)); % Create New Right Y-Tick Labels
set(Ax(2), 'YTick',newytr, 'YTickLabel',newytrl); % Set New Right Y-Tick Labels
ytl = get(Ax(1), 'YTick'); % Get Default Left Y-Yick Values
newytl = linspace(min(ytl), max(ytl), 12); % Create New Left Y-Tick Values
newytll = round(newytl,1); % Create New Left Y-Tick Labels
set(Ax(1), 'YTick',newytl, 'YTickLabel',newytll); % Set New Left Y-Tick Labels
xt = get(gca, 'XTick');
set(gca, 'XTick',xt, 'XTickLabel',xt*1E+6)
xlabel('Time (ns)')

Star Strider
2019 年 5 月 3 日
Those are the constraints of the plotyy function. The only way I can think of to add markers to the other plots, since plotyy only permits certain line styles, is to plot the marker specifically in another plot call. So if you want to add green upward-pointing tirangles to ‘Standard Vth’, use this:
plot(plotData(:,7),plotData(:,8),'^g')
That should work.
Rai
2019 年 5 月 3 日
I try this but it was not working if I leave the markers it still okay but the line width is too samll. Is there any way I change the widths of all graphs.
Star Strider
2019 年 5 月 3 日
That does not appear to ba an option with plotyy.
Rai
2019 年 5 月 3 日
okay thank so much Strider for your help and time.
Star Strider
2019 年 5 月 3 日
My pleasure.
Rai
2019 年 5 月 3 日
I try to use 'bold' command to make my all three axis to be more visible but no success for me. Is it possible to it them bold? or not. I need help regarding bold command in the code where I have to do it
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
