Seaborn barplot တွင်ဘားများ၏အရောင်သတ်မှတ်နည်း


အဏ္ဏဝါ ဘားကွက်တစ်ခုတွင် ဘားများ၏အရောင်ကို သတ်မှတ်ရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။

နည်းလမ်း 1- ဘားများအားလုံးအတွက် အရောင်သတ်မှတ်ပါ။

 #use steelblue for the color of all bars
sns. barplot (x=xvar, y=yvar, color=' steelblue ')

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

 #use orange for bar with max value and gray for all other bars
cols = [' gray ' if (x < max (df. yvar )) else ' orange ' for x in df. yvar ]

#create barplot using specified colors
sns. barplot (x=df. xvar , y=df. yvar , palette=cols)

နည်းလမ်း 3- အခြေအနေပေါ်အခြေခံ၍ ဘားအရောင်သတ်မှတ်ပါ။

 #use red for bars with value less than 10 and green for all other bars
cols = [' red ' if x < 10 else ' green ' for x in df. yvar ]

#create barplot using specified colors
sns. barplot (x=df. xvar , y=df. yvar , palette=cols)

အောက်ဖော်ပြပါနမူနာများသည် အောက်ပါ pandas DataFrame ဖြင့် လက်တွေ့တွင် နည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' employee ': ['Andy', 'Bert', 'Chad', 'Doug', 'Eric', 'Frank'],
                   ' sales ': [22, 14, 9, 7, 29, 20]})

#view DataFrame
print (df)

  employee sales
0 Andy 22
1 Bert 14
2 Chad 9
3 Doug 7
4 Eric 29
5 Frank 20

ဥပမာ 1- ဘားများအားလုံးအတွက် အရောင်သတ်မှတ်ပါ။

အောက်ဖော်ပြပါကုဒ်သည် Seaborn တွင် barplot တစ်ခုကိုဖန်တီးနည်းကိုပြသပြီး ကွက်လပ်ရှိဘားများအားလုံးအတွက် “ steelblue” အရောင်ကိုအသုံးပြုသည်-

 import seaborn as sns

#create barplot using steelblue as color for each bar
sns. barplot (x= df.employee ,y= df.sales ,color=' steelblue ')

ဥပမာ 2- အမြင့်ဆုံးတန်ဖိုးဖြင့် ဘားအရောင်ကို သတ်မှတ်ပါ။

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

 import seaborn as sns

#use orange for bar with max value and gray for all other bars
cols = [' gray ' if (x < max (df. sales )) else ' orange ' for x in df. dirty ]

#create barplot with custom colors
sns. barplot (x=df. employee , y=df. sales , palette=cols) 

seaborn barplot သည် အမြင့်ဆုံးတန်ဖိုးဖြင့် ဘားအရောင်သတ်မှတ်ထားသည်။

ဥပမာ 3- အမြင့်ဆုံးတန်ဖိုးဖြင့် ဘားအရောင်ကို သတ်မှတ်ပါ။

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

 import seaborn as sns

#use red for bars with value less than 10 and green for all other bars
cols = [' red ' if x < 10 else ' green ' for x in df. dirty ]

#create barplot with custom colors
sns. barplot (x=df. employee , y=df. sales , palette=cols) 

အခြေအနေပေါ်မူတည်၍ အရောင်များဖြင့် Seaborn bar ကွက်ကွက်

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

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

Seaborn တွင် အုပ်စုဖွဲ့ barplot ဖန်တီးနည်း
Seaborn တွင် Pie Chart ဖန်တီးနည်း
ပုံတစ်ပုံတည်းတွင် များစွာသော Seaborn Plots များကို ဖန်တီးနည်း

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

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