change the lines' widths in a stem plot, without changing the markers edges widths?

11 ビュー (過去 30 日間)
Sim
Sim 2020 年 10 月 21 日
編集済み: Adam Danz 2020 年 10 月 21 日
Hi, how can I change the lines' widths in a stem plot, without changing the markers edges' widths?
(I just want to modifiy the lines's widths and not the markers edges' thickness, either)
Example:
x = 1:10;
y = [2 5 4 1 2 4 1 8 1 2];
stem(x,y,'LineWidth',0.1,'MarkerSize',15,'MarkerFaceColor','g')
and I get this:
Instead if I change the LineWidth property as:
stem(x,y,'LineWidth',3,'MarkerSize',15,'MarkerFaceColor','g')
I get this:

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
編集済み: Ameer Hamza 2020 年 10 月 21 日
You will need to use a combination of stem and scatter to get such a result. Check the following code
x = 1:10;
y = rand(1,10);
subplot(3,1,1)
stem(x,y,'LineWidth',2,'MarkerSize',15,'MarkerFaceColor','g')
subplot(3,1,2)
stem(x,y,'LineWidth',2,'MarkerSize',15,'MarkerFaceColor','g', 'MarkerEdgeColor', 'none')
subplot(3,1,3)
hold on
stem(x, y, 'LineWidth', 2, 'Marker', 'none')
scatter(x, y, 'filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'g', 'SizeData', 200, 'LineWidth', 0.5)
  1 件のコメント
Sim
Sim 2020 年 10 月 21 日
Thanks a lot to everyone! I would accept all of your answers!

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

その他の回答 (2 件)

Adam Danz
Adam Danz 2020 年 10 月 21 日
編集済み: Adam Danz 2020 年 10 月 21 日
Method 1: Set markers separately
x = 1:10;
y = [2 5 4 1 2 4 1 8 1 2];
figure()
stem(x,y,'b-','LineWidth',3,'Marker','none')
hold on
plot(x,y,'bo','MarkerSize',15,'MarkerFaceColor','g')
Method 2: Remove edges from marker
figure()
stem(x,y,'b-','LineWidth',3,'MarkerSize',15,'MarkerFaceColor','g','MarkerEdgeColor','none')
  1 件のコメント
Sim
Sim 2020 年 10 月 21 日
Thanks a lot to everyone! I would accept all of your answers!

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


Chenguang Yan
Chenguang Yan 2020 年 10 月 21 日
You can change the value of h2.SizeData to adapt to h1.LineWidth
close all
x = 1:10;
y = [2 5 4 1 2 4 1 8 1 2];
h1 = stem(x,y,'LineWidth',3,'MarkerSize',15,'MarkerFaceColor','g','MarkerEdgeColor','g');
hold on
h2 = scatter(x,y,'LineWidth',0.1,"SizeData",300,"MarkerEdgeColor",'#0072BD');
  1 件のコメント
Sim
Sim 2020 年 10 月 21 日
Thanks a lot to everyone! I would accept all of your answers!

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by