Matplotlib ရှိ ဒဏ္ဍာရီတစ်ခု၏ အနေအထားကို မည်သို့ပြောင်းလဲမည်နည်း။
Matplotlib ရှိ ဒဏ္ဍာရီတစ်ခု၏ အနေအထားကို ပြောင်းလဲရန်၊ သင်သည် plt.legend() လုပ်ဆောင်ချက်ကို အသုံးပြုနိုင်သည်။
ဥပမာအားဖြင့်၊ သင်သည် ဇာတ်ကွက်၏ ဘယ်ဘက်အပေါ်ထောင့်တွင် ဒဏ္ဍာရီကို ထားရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်သည်။
plt. legend (loc=' upper left ')
မူရင်းတည်နေရာသည် “ အကောင်းဆုံး” ဖြစ်သည် – ဤနေရာတွင် Matplotlib သည် ဒေတာအချက်များကို ဖုံးကွယ်ထားခြင်းမရှိသော ဒဏ္ဍာရီအတွက် တည်နေရာကို အလိုအလျောက်ရှာတွေ့သည်။
သို့သော်၊ သင်သည် အောက်ပါစာတန်းတည်နေရာများထဲမှ တစ်ခုကို သတ်မှတ်နိုင်သည်-
- ညာဘက်
- ဘယ်ဘက်အပေါ်ထောင့်မှာ
- ဘယ်ဘက်အောက်ခြေမှာ
- အောက်ခြေညာဘက်မှာ
- ညာဘက်
- ဘယ်ဘက်ဗဟို
- ညာယိမ်း
- အောက်ခြေဗဟို
- ထိပ်တန်းစင်တာ
- ဗဟို
ဇာတ်လမ်း၏အပြင်ဘက်တွင် ဒဏ္ဍာရီကို နေရာချထားရန် bbox_to_anchor() အငြင်းအခုံကိုလည်း အသုံးပြုနိုင်သည်။ ဥပမာအားဖြင့်၊ ဇာတ်ကွက်၏အပြင်ဘက်တွင် ဒဏ္ဍာရီကို ညာဘက်အပေါ်ထောင့်တွင် နေရာချရန် အောက်ပါအထားအသိုကို အသုံးပြုနိုင်သည်။
plt. legend (bbox_to_anchor=( 1.05 , 1 ), loc=' upper left ', borderaxespad= 0 )
အောက်ဖော်ပြပါ ဥပမာများသည် ဤနည်းလမ်းတစ်ခုစီကို လက်တွေ့အသုံးချနည်းကို ပြသထားသည်။
ဥပမာ 1- Matplotlib ဇာတ်ကွက်အတွင်း ဒဏ္ဍာရီ၏ အနေအထားကို ပြောင်းပါ။
အောက်ပါကုဒ်သည် Matplotlib မျဉ်းကွက်တစ်ခု၏ ညာဘက်အလယ်ဗဟိုတွင် ဒဏ္ဍာရီကို မည်သို့ထားရမည်ကို ပြသသည်-
import pandas as pd import matplotlib. pyplot as plt #createdata df = pd. DataFrame ({' points ': [11, 17, 16, 18, 22, 25, 26, 24, 29], ' assists ': [5, 7, 7, 9, 12, 9, 9, 4, 8]}) #add lines to plot plt. plot (df[' points '], label=' Points ', color=' green ') plt. plot (df[' assists '], label=' Assists ', color=' steelblue ') #place legend in center right of plot plt. legend (loc=' center right ', title=' Metric ')
အောက်ဖော်ပြပါကုဒ်သည် ဒဏ္ဍာရီကို Matplotlib ကွက်ကွက်တစ်ခု၏ ဘယ်ဘက်အပေါ်ပိုင်းတွင် မည်သို့ထားရမည်ကို ပြသသည်-
import pandas as pd import matplotlib. pyplot as plt #create data df = pd. DataFrame ({' points ': [11, 17, 16, 18, 22, 25, 26, 24, 29], ' assists ': [5, 7, 7, 9, 12, 9, 9, 4, 8]}) #add lines to plot plt. plot (df[' points '], label=' Points ', color=' green ') plt. plot (df[' assists '], label=' Assists ', color=' steelblue ') #place legend in center right of plot plt. legend (loc=' upper left ', title=' Metric ')
ဥပမာ 2- Matplotlib ဇာတ်ကွက်ပြင်ပ ဒဏ္ဍာရီ၏ အနေအထားကို ပြောင်းပါ။
ဒဏ္ဍာရီကို Matplotlib ကွက်ကွက်တစ်ခု၏ အပြင်ဘက်တွင် ထားရှိရန်၊ ကျွန်ုပ်တို့သည် bbox_to_anchor() အငြင်းအခုံကို အသုံးပြုနိုင်ပါသည်။
ဥပမာ၊ ဤနေရာတွင် ဒဏ္ဍာရီကို ဇာတ်ကွက်၏ ညာဘက်အပေါ်ထောင့်အပြင်ဘက်တွင် မည်သို့ထားရှိရမည်နည်း။
import pandas as pd import matplotlib. pyplot as plt #create data df = pd. DataFrame ({' points ': [11, 17, 16, 18, 22, 25, 26, 24, 29], ' assists ': [5, 7, 7, 9, 12, 9, 9, 4, 8]}) #add lines to plot plt. plot (df[' points '], label=' Points ', color=' green ') plt. plot (df[' assists '], label=' Assists ', color=' steelblue ') #place legend in center right of plot plt. legend (bbox_to_anchor=( 1.02 , 1 ), loc=' upper left ', borderaxespad= 0 )
ဤသည်မှာ ဒဏ္ဍာရီကို ဇာတ်ကွက်၏အောက်ခြေညာဘက်ထောင့်အပြင်ဘက်တွင် မည်သို့ထားရှိရမည်နည်း၊
import pandas as pd import matplotlib. pyplot as plt #create data df = pd. DataFrame ({' points ': [11, 17, 16, 18, 22, 25, 26, 24, 29], ' assists ': [5, 7, 7, 9, 12, 9, 9, 4, 8]}) #add lines to plot plt. plot (df[' points '], label=' Points ', color=' green ') plt. plot (df[' assists '], label=' Assists ', color=' steelblue ') #place legend in center right of plot plt. legend (bbox_to_anchor=( 1.02 , 0.1 ), loc=' upper left ', borderaxespad= 0 )
bbox_to_anchor() အငြင်းအခုံ၏အသေးစိတ်ရှင်းပြချက်အတွက် matplotlib စာရွက်စာတမ်းကို ကိုးကားပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် Matplotlib ရှိ အခြားသော ဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Matplotlib တွင် ဒဏ္ဍာရီဖောင့်အရွယ်အစားကို မည်သို့ပြောင်းလဲမည်နည်း။
Matplotlib ရှိ ဒဏ္ဍာရီသို့ ခေါင်းစဉ်တစ်ခုထည့်နည်း
Matplotlib တွင် ခေါင်းစဉ်အနေအထားကို ချိန်ညှိနည်း
Matplotlib ရှိ ဝင်ရိုးအညွှန်းတည်နေရာကို ချိန်ညှိနည်း