Matplotlib ကွက်များသို့ စာသားထည့်နည်း (ဥပမာများဖြင့်)
အောက်ပါ syntax ကိုအသုံးပြု၍ matplotlib.pyplot.text() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ Matplotlib ကွက်သို့ စာသားကို အလွယ်တကူ ထည့်နိုင်သည်-
matplotlib.pyplot.text(x၊ y၊ s၊ fontdict=None)
ရွှေ-
- x- စာသား၏ x သြဒိနိတ်
- y- စာသား၏ y သြဒိနိတ်
- s: စာသား စာကြောင်း
- fontdict- မူရင်းစာသားဂုဏ်သတ္တိများကို အစားထိုးရန် အဘိဓာန်
ဤသင်ခန်းစာတွင် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးပြုပုံ နမူနာများစွာကို ပြသထားသည်။
ဥပမာ 1- Matplotlib ကွက်ကွက်တွင် ထူးခြားသောစာသားကို ထည့်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် အပိုင်းအစတစ်ခုကို ဖန်တီးပုံနှင့် ကွက်ကွက်ထဲသို့ စာသားတစ်ပိုင်းကို ထည့်နည်းကို ပြသသည်-
import matplotlib. pyplot as plt
#createdata
x = [3, 6, 8, 12, 14]
y = [4, 9, 14, 12, 9]
#create scatterplot
plt. scatter (x,y)
#add text at (x, y) coordinates = (6, 9.5)
plt. text (6, 9.5, ' Here we go ')
ဥပမာ 2- Matplotlib ကွက်သို့ စာသားများစွာကို ထည့်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် အပိုင်းအစတစ်ခု ဖန်တီးပုံနှင့် ကွက်ကွက်ထဲသို့ စာသားများစွာကို ပေါင်းထည့်နည်းကို ပြသသည်-
import matplotlib. pyplot as plt
#create data
x = [3, 6, 8, 12, 14]
y = [4, 9, 14, 12, 9]
#create scatterplot
plt. scatter (x,y)
#add text at (x, y) coordinates = (6, 9.5)
plt. text (6, 9.5, ' A piece of text ')
#add another piece of text
plt. text (8, 13, ' Another piece of text ')
ဥပမာ 3- စာသားဂုဏ်သတ္တိများကို တည်းဖြတ်ပါ။
စာသားဂုဏ်သတ္တိများကို ပြောင်းလဲရန် ဖောင့်ဂုဏ်သတ္တိများကို သတ်မှတ်သည့် အဘိဓာန်တစ်ခုကို ဖန်တီးနိုင်သည်။
အောက်ပါကုဒ်သည် ၎င်းကိုပြုလုပ်နည်းကို ပြသသည်-
import matplotlib. pyplot as plt
#createdata
x = [3, 6, 8, 12, 14]
y = [4, 9, 14, 12, 9]
#create scatterplot
plt. scatter (x,y)
font = {' family ': ' serif ',
' color ': ' red ',
' weight ': ' bold ',
' size ': 20
}
#add text with custom font
plt. text (6, 9.5, ' A piece of text ', fontdict=font)
ဥပမာ 4- စာသားပတ်လည်ဘောင်တစ်ခုထည့်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် စာသားတစ်ဝိုက်တွင် ဘောင်တစ်ခုထည့်နည်းကို ပြသသည်-
import matplotlib. pyplot as plt
#createdata
x = [3, 6, 8, 12, 14]
y = [4, 9, 14, 12, 9]
#create scatterplot
plt. scatter (x,y)
font = {' family ': ' serif ',
' color ': ' red ',
' weight ': ' bold ',
' size ': 20
}
box = {' facecolor ': ' none ',
' edgecolor ': ' green ',
' boxstyle ': ' round '
}
#add text with custom font
plt. text (6, 9.5, ' A piece of text ', fontdict=font, bbox=box)
ထပ်လောင်းအရင်းအမြစ်များ
Matplotlib အပိုင်းအစများကို မှတ်သားနည်း
Matplotlib ကွက်တွင် ဖောင့်အရွယ်အစားကို မည်သို့ပြောင်းလဲမည်နည်း။