Matplotlib ဘားများ
ဘားများဖန်တီးခြင်း။
Pyplot ဖြင့်၊ သင်သည် bar()
ဘားဂရပ်များကိုဆွဲရန် လုပ်ဆောင်ချက်ကို အသုံးပြုနိုင်သည်။
ဥပမာ
ဘား 4 ခုဆွဲပါ
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x,y)
plt.show()
ရလဒ်:
လုပ်ဆောင်ချက်သည် bars များ၏ layout ကို ဖော်ပြသော bar()
arguments များကိုယူသည်။
အမျိုးအစားများနှင့် ၎င်းတို့၏တန်ဖိုးများကို arrays အဖြစ် ပထမ နှင့် ဒုတိယ အငြင်းအခုံများ ဖြင့် ကိုယ်စားပြုသည် ။
ဥပမာ
x = ["APPLES", "BANANAS"]
y = [400, 350]
plt.bar(x, y)
အလျားလိုက် ဘားများ
ဘားများကို ဒေါင်လိုက်အစား အလျားလိုက်ပြသလိုပါက၊ barh()
လုပ်ဆောင်ချက်ကို အသုံးပြုပါ-
ဥပမာ
အလျားလိုက် ဘား 4 ခု ဆွဲပါ
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.barh(x, y)
plt.show()
ရလဒ်:
ဘားအရောင်
ဘား များ၏ အရောင်ကိုသတ်မှတ်ရန် အဓိကစကားလုံးအငြင်းအခုံကို ယူဆောင်သည်
bar()
-barh()
color
ဥပမာ
အနီရောင်ဘား 4 ခုဆွဲပါ
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x, y, color = "red")
plt.show()
ရလဒ်:
အရောင်အမည်များ
ပံ့ပိုးပေးထားသော အရောင်အမည် 140 ထဲမှ တစ်ခုခုကို သင်သုံးနိုင်သည် ။
ဥပမာ
"ပူသောပန်းရောင်" ဘား 4 ခုဆွဲပါ။
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x, y, color = "hotpink")
plt.show()
ရလဒ်:
အရောင် Hex
သို့မဟုတ် Hexadecimal အရောင်တန်ဖိုးများ ကို သင်သုံးနိုင်သည် -
ဥပမာ
လှပသော အစိမ်းရင့်ရောင်ဖြင့် ဘား 4 ခုကို ဆွဲပါ။
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x, y, color = "#4CAF50")
plt.show()
ရလဒ်:
ဘားအကျယ်
bars ၏ width ကိုသတ်မှတ်ရန် bar()
keyword argument
ကိုယူသည်-width
ဥပမာ
အလွန်ပါးလွှာသော အကန့် ၄ ခုကို ဆွဲပါ။
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x, y, width = 0.1)
plt.show()
ရလဒ်:
မူရင်းအကျယ်တန်ဖိုးသည် 0.8 ဖြစ်သည်။
မှတ်ချက်- အလျားလိုက်ဘားများအတွက်၊ height
အစား width
.
ဘားအမြင့်
bars များ၏ အမြင့်ကိုသတ်မှတ်ရန် barh()
keyword argument
ကိုယူသည်-height
ဥပမာ
အလွန်ပါးလွှာသော အကန့် ၄ ခုကို ဆွဲပါ။
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A",
"B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.barh(x, y, height = 0.1)
plt.show()
ရလဒ်:
မူရင်းအမြင့်တန်ဖိုးမှာ 0.8 ဖြစ်သည်။