How to improve my code for getting the output in the picture?

2 次查看(过去 30 天)
I want a output similar to this
the code I wrote is
R=1.09677*10^7;
p=1;
n=2;
Z=1
for n= 2:9
n=n+1;
k=R*Z^2*[1/(p^2)-1/(n^2)];
lamda=1/k
y=linspace(0,7*10^-9,20)
plot(lamda,y)
hold on
daspect([1,1,1])
endfor
here i am getting output as groups of points since i wrote plot(lamda,y)
  • what can i do to get a line instead of group of points
  • how to change the background to black
  • is there any way to change the colour of the line (plot) according to the wavelength
  • can we change the thickness?

采纳的回答

Star Strider
Star Strider 2017-12-10
Try this:
R=1.09677E+7;
p=1;
n=2;
Z=1;
for n= 2:9
n=n+1;
k=R*Z^2*[1/(p^2)-1/(n^2)];
lamda=1/k;
y=linspace(0,7E-9,20);
plot(lamda*ones(size(y)),y)
hold on
daspect([1,1,1])
end
set(gca, 'Color','k')
  2 个评论
Pijush
Pijush 2017-12-10
this is great. can we somehow change the colour of line too and yeah can we make the lines appear a little thicker?
Star Strider
Star Strider 2017-12-10
Try this:
R=1.09677E+7;
p=1;
n=2;
Z=1;
cm = colormap(jet(9));
for n= 2:9
k=R*Z^2*[1/(p^2)-1/(n^2)];
lamda=1/k;
y=linspace(0,7E-9,20);
plot(lamda*ones(size(y)),y, 'Color',cm(n,:), 'LineWidth',2)
hold on
end
daspect([1,1,1])
axis([xlim 0 max(y)])
set(gca, 'Color','k')
See the documentation on colormap to understand its options.
Experiment to get the result you want.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by