4つの点を通る一本の直線をグラフで引く方法
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
次のような線を定義しているときに,一本の線でグラフを引きたいです.
obj.Map{1} = [-8, -4; 6, -4];
obj.Map{2} = [ 6, -4; 6, 4];
obj.Map{3} = [ 6, 4; -8, 4];
obj.Map{4} = [-8, 4; -8, -4];
(書き方は[xa,ya;xb,yb]となっており,aとbを結ぶ直線を定義しています.)
ここで普通にplotでグラフを出しても,凡例には4本の直線が出てきます.
しかし私は,この線で壁であることを示したいので凡例としては一本の線で「Wall」と示したいのです.
どうすれば一番良いのでしょうか.
0 commentaires
Réponses (2)
Musashi Ito
le 17 Mar 2020
Modifié(e) : Musashi Ito
le 17 Mar 2020
ご参考までに、plot 関数で同じ色でプロットして、legend 関数で凡例を追加する方法はいかがでしょうか。
a = [-8 -4; 6 -4];
b = [ 6 -4; 6 4];
c = [ 6 4;-8 4];
d = [-8 4;-8 -4];
% グラフの作成
figure
plot([a(1,1) a(2,1)],[a(1,2) a(2,2)],'b-')
hold on
plot([b(1,1) b(2,1)],[b(1,2) b(2,2)],'b-')
plot([c(1,1) c(2,1)],[c(1,2) c(2,2)],'b-')
plot([d(1,1) d(2,1)],[d(1,2) d(2,2)],'b-')
hold off
xlim([-10 8])
ylim([-6 6])
grid on
% 凡例の追加
legend('Wall','FontSize',12)
0 commentaires
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!