Pandas- plot legends ကို ဖန်တီးပြီး စိတ်ကြိုက်လုပ်နည်း


ပန်ဒါများထဲမှ ဒဏ္ဍာရီတစ်ခုသို့ ဒဏ္ဍာရီတစ်ခုထည့်ရန် အောက်ပါအခြေခံ syntax ကို သင်အသုံးပြုနိုင်သည်-

 plt. legend ([' A ',' B ',' C ',' D '], loc=' center left ', title=' Legend Title ')

အောက်ဖော်ပြပါ ဥပမာသည် ဤ syntax ကို လက်တွေ့တွင် မည်သို့အသုံးပြုရမည်ကို ပြသထားသည်။

ဥပမာ- Pandas ရှိ Plot Legend တစ်ခုကို ဖန်တီးပြီး စိတ်ကြိုက်လုပ်ပါ။

ကျွန်ုပ်တို့တွင် အောက်ပါ ပန်ဒါ DataFrame ရှိသည် ဆိုပါစို့။

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' A ':7, 'B':12, ' C ':15, ' D ':17}, index=[' Values '])

DataFrame ရှိ တန်ဖိုးများကို မြင်သာစေရန်နှင့် စိတ်ကြိုက်တံဆိပ်များဖြင့် ဒဏ္ဍာရီတစ်ခုကို ထည့်ရန် ဘားကားချပ်တစ်ခု ဖန်တီးရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။

 import matplotlib. pyplot as plt

#create bar chart
df. plot (kind=' bar ')

#add legend to bar chart
plt. legend ([' A Label ',' B Label ',' C Label ',' D Label '])

ဒဏ္ဍာရီ၏တည်နေရာနှင့် ခေါင်းစဉ်ကို မွမ်းမံပြင်ဆင်ရန် loc argument နှင့် title argument တို့ကိုလည်း အသုံးပြုနိုင်ပါသည်။

 import matplotlib. pyplot as plt

#create bar chart
df. plot (kind=' bar ')

#add custom legend to bar chart
plt. legend ([' A Label ', ' B Label ', ' C Label ', ' D Label '],
            loc=' upper left ', title=' Labels ') 

နောက်ဆုံးအနေနဲ့၊ ဒဏ္ဍာရီထဲက ဖောင့်အရွယ်အစားကို မွမ်းမံဖို့အတွက် အရွယ်အစား အကြောင်းပြချက်ကို အသုံးပြုနိုင်ပါတယ်။

 import matplotlib. pyplot as plt

#create bar chart
df. plot (kind=' bar ')

#add custom legend to bar chart
plt. legend ([' A Label ', ' B Label ', ' C Label ', ' D Label '], prop={' size ': 20 }) 

စာတန်းရှိ ဖောင့်အရွယ်အစားသည် ယခု ပိုမိုကြီးမားလာသည်ကို သတိပြုပါ။

ထပ်လောင်းအရင်းအမြစ်များ

အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-

Pandas DataFrame မှ Pie Chart ဖန်တီးနည်း
Pandas DataFrame မှ point cloud တစ်ခုကို ဖန်တီးနည်း
Pandas DataFrame မှ histogram တစ်ခုဖန်တီးနည်း

မှတ်ချက်တစ်ခုထည့်ပါ။

သင့် email လိပ်စာကို ဖော်ပြမည် မဟုတ်ပါ။ လိုအပ်သော ကွက်လပ်များကို * ဖြင့်မှတ်သားထားသည်