折れ線グラフの指定範囲の背景塗りつぶし

16 views (last 30 days)
daiki naito
daiki naito on 24 Apr 2022
Commented: daiki naito on 25 Apr 2022
折れ線グラフをプロットする際に、Xの範囲(例 15〜30の範囲)を指定して背景を塗りつぶす方法を教えていただけないでしょうか。

Answers (1)

Atsushi Ueno
Atsushi Ueno on 25 Apr 2022
Edited: Atsushi Ueno on 25 Apr 2022
直接座標を指定して多角形を描画する方法です。専用に作られた関数を使えば便利です。
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129];
y = [0.259454378238583,0.259004977396962,0.257646462597382,0.255347542836678,0.252054888013056,0.247691376816408,0.242153707189854,0.235309523525177,0.226994434437369,0.217009747805742,0.205122649074174,0.191072284861455,0.174588456510459,0.155435362566237,0.133501896170380,0.108970674541884,0.0825978805926125,0.0560847480074129,0.0323470664907240,0.0152209963651520,0.00826167699292209,0.0133352843308549,0.0303157428089811,0.0577438312133592,0.0933560579153112,0.134267582551197,0.176994138320251,0.217422958749508,0.250993951298588,0.273312061929103,0.281069072787965,0.272869810339360,0.249592983327744,0.214195956568856,0.171126683148973,0.125563882236923,0.0826267061545953,0.0466339906562952,0.0205156088886258,0.00551343119378952,0.00125822862168003,0.00616898130830241,0.0179899795079182,0.0342500755023087,0.0525046964778593,0.0703578373235337,0.0854177491880969,0.0954538882458391,0.0989222364718208,0.0955991112542102,0.0867352694754039,0.0745396741361097,0.0614968721296211,0.0500256242481008,0.0424113398795707,0.0405338833448603,0.0449845180887058,0.0538724523197632,0.0628274347563910,0.0677095008135013,0.0683090987416723,0.0683858044589300,0.0714187762300518,0.0773695216340898,0.0834207273249916,0.0863552160976316,0.0841127582375293,0.0761673964433882,0.0628290861483002,0.0437677999799914,0.0202067670415977,0.00328750578895579,0.00750703913219124,0.0311739750191599,0.0601827782938302,0.0820940124377758,0.0899322129566095,0.0803172011702681,0.0536029160642848,0.0199137431030236,0.00143298355870241,0.00190935381402386,0.00773506804070442,0.0248492393657597,0.0485613752894280,0.0673646905454522,0.0759562105976397,0.0736705499377871,0.0617630821000930,0.0430733315745309,0.0229233897751331,0.00831116873145782,0.00245527785212243,0.00283375992898396,0.0164972942453561,0.0695139639368728,0.152690814024784,0.203228613030337,0.202927817538004,0.171949776373283,0.128475810724997,0.0845918309796656,0.0492236780909716,0.0273908328378636,0.0186624140232090,0.0199040388577439,0.0297448724321350,0.0476328732633558,0.0701238961966722,0.0908670284045613,0.103257848443643,0.102543890856631,0.0871912395829366,0.0603925411687535,0.0308059468028943,0.00961575128100642,0.00371552956888479,0.0115550182933975,0.0266686013138599,0.0435826622119758,0.0595419733708523,0.0732090039101967,0.0835632107952355,0.0895605474880568,0.0900487337318863,0.0838213846009304,0.0703594358600914,0.0529856582073242,0.0438477253138947];
patch([15 30 30 15], [0 0 0.3 0.3], 'cyan', 'EdgeColor', 'none');
hold on
plot(x,y);
  1 Comment
daiki naito
daiki naito on 25 Apr 2022
ありがとうございます。教えていただいた方法を参考にさせていただきます。

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!