How to do this kind of contour plot?
2 次查看(过去 30 天)
显示 更早的评论
I just want to plot a graph like this:
I know it's a contour plot, but I don't know how to do it.
I wanna plot several curves (as shown in the figure) vs another parameter, for example:
Curve 1: X-Axis --> Voltage | Y-Axis --> Current | For T = 10ºC
Curve 2: X-Axis --> Voltage | Y-Axis --> Current | For T = 20ºC
Curve 3: X-Axis --> Voltage | Y-Axis --> Current | For T = 40ºC
Curve 4: X-Axis --> Voltage | Y-Axis --> Current | For T = 60ºC
Curve 5: X-Axis --> Voltage | Y-Axis --> Current | For T = 80ºC
Somebody could help me? Thanks in advance.
2 个评论
采纳的回答
jonas
2018-5-9
Basically you don't define data along lines but rather on a full rectangular grid. Let's say you want to plot data between x=0:10 and y=0:10.
x=0:10;
y=0:10;
[X,Y]=meshgrid(x,y)
This will give you a grid (11x11). Now define the function Z(Y,X) which you want to plot. For example:
Z=X.^2+Y.^2
[C,h]=contour(X,Y,Z)
You can also define the number of contours as a fourth argument. Finally, you can label the contours by adding:
clabel(C,h)
Hope this helps
6 个评论
jonas
2018-5-15
Hi again, sorry for the late reply. Based on the comments, what you want is an ordinary plot, like this:
h=plot(x,y1,...
x,y2,...
x,y3) %and so on
You can also add labels using text. Adding a colorbar to a 2d-plot is not as trivial, but it can be done by setting the line colors based on a colormap and a temperature vector, or alternatively by using something like this non-default function 3d color line (link)
This will not give you a plot identical to the one in your figure, which I believe is a surface plot (with data on a full rectangular grid). If you want to obtain similar results, then there are some different solutions. To be honest, having both colors AND clabels (as in the figure) is however unnecessary. Anyway, let me know if you still want that.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!