Vary the thickness of plot

41 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 10 日
コメント済み: Walter Roberson 2019 年 11 月 11 日
I am potting multiple plots on one axis and I want to vary the thickness of plots based on their absolute value.
How can I do that?
  1 件のコメント
Shubham Gupta
Shubham Gupta 2019 年 11 月 11 日
Can you provide some example, to understand what do mean by "absolute value" of a plot?

サインインしてコメントする。

回答 (3 件)

Walter Roberson
Walter Roberson 2019 年 11 月 11 日
In MATLAB, any one primitive line object, or any one mesh or surface or patch's edge, has constant width. You can do a bit with arrow heads, but not very much, really.
A line can be broken up into line segments that are created with individual line object, each of which is a constant size. But if you have widths computed according to the value associated with a point, then you need to decide how you are going to compute the width between the point and the previous point, or the point and the next point.
About the only way I can think of to get variable thickness of lines is to use patch objects to draw the lines, using trapazoids, such as (x1, y1+width1/2) to (x2, y2+width2/2) to (x2, y2-width2/2) to (x1, y1-width1/2) back to (x1, y1+width1/2) and color that face with the color to be associated with the line.
There is a file exchange contribution for drawing lines with variable color by using patches, that you could probably adapt.
  2 件のコメント
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 11 日
What you mean by width1/2 or width2/2? and what is patch here?
By the way can I change the size of points by their absolute value? The bigger the absolute value, the larger diamter would that specific point have.
Walter Roberson
Walter Roberson 2019 年 11 月 11 日
patch is https://www.mathworks.com/help/matlab/ref/patch.html which is a fundamental graphics routine for creating arbitrary lines and faces.
You want to vary your line width according to absolute value of something. You have information associated with each point that can be used to compute the corresponding width for each point. Suppose that you have computed all of those values and stored them in a variable named Widths, one entry for each X, and assuming you have the same number of Y. Then
xt = x(:);
xv = [xt; flipud(xt)]; %up to maximum, back to beginning
yt = y(:);
yv = [yt - Widths(:)/2; flipud(yt + Widths(:)/2)];
fill(xv, yv)
This draws a variable-width box around the coordinates.
By the way can I change the size of points by their absolute value?
scatter() can easily handle different size of points each, but any one primitive line object can only have a constant-sized point.
It is relatively easy to do something like
plot(x, y);
hold on
scatter(x, y, Widths);
hold off

サインインしてコメントする。


Akira Agata
Akira Agata 2019 年 11 月 11 日
How about using daspect function?
The following is an example.
d1 = rand(1,10);
d2 = rand(1,10)*10;
figure
ax1 = subplot(1,2,1);
plot(d1)
ax2 = subplot(1,2,2);
plot(d2)
daspect(ax1,[1 1 1]);
daspect(ax2,[1 1 1]);
plot.png
  3 件のコメント
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 11 日
@Akira Agata Thanks for the suggestion but I meant the thickness of plot not the size of axis.
Image Analyst
Image Analyst 2019 年 11 月 11 日
That's why I suggested 'LineWidth" in my Answer. But your question is very ambiguous -- that's why you may not have the answer you want yet. Please try to post a screenshot of exactly what you'd like to see. Use the green frame icon.

サインインしてコメントする。


Image Analyst
Image Analyst 2019 年 11 月 11 日
Do you mean LineWidth of the curve your data makes when plotting it with plot(), like
lineWidth = round(min([1, mean(y)]); % or 2, 3, 4 or whatever width you want
plot(x, y, 'LineWidth', lineWidth);

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by