Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. วิธีเพิ่ม Legends และ Title ให้ Grouped Histograms จาก Pandas

    การเพิ่ม Legend และ Title ให้ Grouped Histograms ใช้ df.plot(kind=hist) แล้วเพิ่ม title ด้วย plt.title() ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้าง DataFrame พร้อมคอลัมน์ a, b, c, d พล็อตด้วย df.plot(kind=hist) ตั้งค่า title ด้วย plt.title() แสดงผลด้วย show() ตัวอย่างโค้ด from matplotli

  2. วิธีสร้างลูกศรสองหัว (Double-headed Arrow) บนแกนใน Matplotlib

    การสร้างลูกศรสองหัวบนแกนพิกัด ใช้ annotate() พร้อม arrowstyle=<-> ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding ใช้ annotate() ระบุ xy (ปลาย), xytext (ต้น), arrowprops ใน arrowprops: arrowstyle=<-> (สองหัว), color=red แสดงผลด้วย show() ตัวอย่างโค้ด import matplotlib.pyplot as plt plt.

  3. วิธีแทนที่ค่า Relative ด้วย Absolute Values ใน Matplotlib Pie Chart

    การแสดงค่าสัมบูรณ์แทนเปอร์เซ็นต์ใน Pie Chart ใช้ autopct=lambda p: {:.0f}%.format(p * total / 100) คำนวณค่าจริงจากเปอร์เซ็นต์ ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding เตรียม labels, fracs, explode และคำนวณ total = sum(fracs) พล็อต pie chart พร้อม autopct lambda function แสดงผลด้วย show() ตัวอ

  4. วิธีแสดงจำนวนนับ (Count) บนแท่ง Histogram ใน Matplotlib

    การแสดงค่า Count บนแท่ง Histogram วนลูปผ่าน patches จาก hist() ใช้ text() วางค่าที่กลางบนแต่ละแท่ง ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding เตรียมข้อมูล list สำหรับ histogram เรียก hist() รับคืน patches วนลูป patches คำนวณตำแหน่งกลาง x และความสูง y ใช้ plt.text(x, y, count) วางข้อความ แสดง

  5. วิธีฝังฟอนต์ใน PDF ที่สร้างโดย Matplotlib

    การฝังฟอนต์ (Embed Fonts) ใน PDF Output ใช้ rcParams[pdf.fonttype] = 42 เพื่อฝังฟอนต์เป็น TrueType (Type 42) ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding ตั้งค่า plt.rcParams[pdf.fonttype] = 42 สร้าง figure และ scatter plot โหลดฟอนต์ TTF ด้วย font_manager.FontProperties ตั้งค่า title ใช้ฟอนต์นั้

  6. วิธีเพิ่มช่องว่างระหว่าง Y-axis และแท่งแรกใน Vertical Bar Chart Matplotlib

    การเพิ่ม Gap ระหว่าง Y-axis และแท่งแรก ปรับ xlim ให้เริ่มต้นก่อนแท่งแรกเล็กน้อย ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้าง x_val, x_names, y_val และกำหนด width, interval พล็อต bar chart ด้วย bar() align=center ตั้งค่า xticks, yticks ปรับ xlim([min(x_val) - 0.5, max(x_val) + 0.5]) ให้มีช่

  7. วิธีส่งค่า RGB Color ให้ Matplotlib Eventplot

    การระบุสี RGB สำหรับ Eventplot ส่งค่าสีเป็น list of tuples (r, g, b) ใน parameter color ของ eventplot() ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้าง array 1D pos สำหรับตำแหน่ง events สร้าง list ของ color tuple (r, g, b) พล็อต parallel lines ด้วย eventplot() แสดงผลด้วย show() ตัวอย่างโค้ด

  8. ความแตกต่างระหว่าง Matplotlib.pyplot และ Matplotlib.figure

    matplotlib.pyplot matplotlib.pyplot เป็นคอลเลกชันของฟังก์ชันที่ทำให้ Matplotlib ทำงานคล้าย MATLAB แต่ละฟังก์ชัน pyplot จะทำการเปลี่ยนแปลงบน figure: สร้าง figure, สร้างพื้นที่พล็อต, พล็อตเส้น, ตกแต่ง labels, เป็นต้น ใน matplotlib.pyplot สถานะต่างๆ จะถูกเก็บรักษาม้ามห้ามข้ามการเรียกฟังก์ชัน จึงติดตามไ

  9. การพล็อต Scatter Points ด้วยสัญลักษณ์ Clover ใน Matplotlib

    การใช้สัญลักษณ์ Clover (♣) ใน Scatter Plot ใช้ LaTeX marker r$\clubsuit$ ใน scatter() ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้างข้อมูล x, y, z (z ใช้เป็น size) พล็อต scatter() พร้อม marker=r$\clubsuit$ ตั้งค่า axis labels และ legend แสดงผลด้วย show() ตัวอย่างโค้ด import matplotlib.pyplo

  10. การปรับ Axis Labels และ Orientation สำหรับ 3D Plots ใน Matplotlib

    การปรับแต่ง Label และ Orientation ของแกน 3D ใช้ linespacing ใน set_xlabel/ylabel/zlabel และ ax.dist สำหรับระยะกล้อง ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้าง figure พร้อม facecolor=w ดึง axes 3D ด้วย projection=3d ตั้งค่า X, Y, Z labels พร้อม linespacing พล็อตข้อมูล 3D ตั้งค่า ax.dist

  11. วิธีพล็อต Signal ใน Matplotlib ด้วย Python

    การพล็อตสัญญาณ (Signal) ใน Domain เวลา แสดงสัญญาณในรูปแบบเวลา-แอมพลิจูด (Time-domain signal) ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding ตั้งค่า random seed, dt, Fs, t สร้างสัญญาณ s ประกอบด้วย sine wave + noise สร้าง figure และ subplots ตั้งค่า title, พล็อต t vs s, ตั้ง xlabel, ylabel แสดงผลด

  12. วิธีพล็อต Magnitude Spectrum ใน Matplotlib ด้วย Python

    การพล็อต Magnitude Spectrum (Linear Scale) ใช้ magnitude_spectrum() แสดง magnitude spectrum แบบ linear scale ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding ตั้งค่า random seed, dt, Fs, t สร้างสัญญาณ s (เหมือน phase spectrum) สร้าง figure และ subplots ตั้งค่า title และพล็อต magnitude_spectrum(s, Fs

  13. วิธีพล็อต Longitudinal Magnitude Spectrum ใน Matplotlib

    การพล็อต Magnitude Spectrum แบบ Longitudinal (dB Scale) ใช้ magnitude_spectrum() พร้อม scale=dB ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding ตั้งค่า random seed, dt, Fs, t สร้างสัญญาณรบกวนและสัญญาณหลัก s สร้าง figure และ subplots ตั้งค่า title และพล็อต magnitude_spectrum(s, Fs=Fs, scale=dB, colo

  14. วิธีวาด Inline Line Labels ใน Matplotlib

    การแสดง Label ตรงบนเส้นกราฟ (Inline Labels) ใช้ไลบรารี labellines และฟังก์ชัน labelLines() ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้างข้อมูล X และพารามิเตอร์ A วนลูปพล็อตแต่ละเส้นพร้อม label เรียก labelLines(plt.gca().get_lines(), zorder=2.5) แสดงผลด้วย show() ตัวอย่างโค้ด import numpy a

  15. วิธีบันทึก Matplotlib 3D Rotating Plots

    การบันทึก 3D Plot ที่หมุนได้ หมุนมุมมอง 3D ด้วย view_init() ในลูป แล้วใช้ plt.draw() และ plt.pause() ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้าง figure และ 3D axes ด้วย projection=3d ดึงข้อมูลทดสอบ 3D ด้วย axes3d.get_test_data() พล็อต wireframe ลูปหมุนมุมมอง 0-360 องศา ด้วย ax.view_init(3

  16. วิธีอัปเดต Matplotlib Figure แบบ Dynamic ตามการเปลี่ยนแปลงไฟล์ข้อมูล

    การอัปเดตกราฟแบบ Real-time เมื่อไฟล์ข้อมูลเปลี่ยน ใช้ plt.pause() ในลูปเพื่อ refresh แสดงผลแบบ dynamic ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding กำหนด m, n สำหรับ grid subplots สร้างรายการสีสุ่ม วนลูป clear และ plot ข้อมูลสุ่มใหม่ในแต่ละ subplot ใช้ plt.pause(0.1) หน่วงเวลาและ refresh display

  17. Vertical Histogram ใน Python และ Matplotlib

    การพล็อต Histogram แนวตั้ง (Vertical) Histogram แนวตั้งเป็นค่าเริ่มต้นของ plt.hist() ใช้ parameter orientation=vertical ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้างรายการข้อมูล x พล็อต histogram ด้วย plt.hist(x, orientation=vertical) แสดงผลด้วย show() ตัวอย่างโค้ด import matplotlib.pyplot a

  18. วิธีสร้างสีหลายสีสำหรับ Pie Chart ใน Matplotlib

    การสร้างสีสุ่มจำนวนมากสำหรับ Pie Chart สร้างสี hex สุ่มจำนวน n สี สำหรับ pie chart ที่มี slice เยอะ ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding กำหนด n = จำนวน slice สร้างข้อมูลสุ่ม a ด้วย numpy สร้างรายการสี hex สุ่ม color สร้าง figure และ axes กำหนด aspect=equal พล็อต pie chart ด้วย plt.pie

  19. วิธีพล็อต Phase Spectrum ใน Matplotlib ด้วย Python

    การพล็อต Phase Spectrum (ซ้ำซ้อนกับ 1004101877) เนื้อหาบทความนี้เหมือนกับ ID 1004101877 ทั้งหมด ใช้ phase_spectrum() แสดง phase spectrum ตัวอย่างโค้ด import matplotlib.pyplot as plt import numpy as np plt.rcParams[figure.figsize] = [7.50, 3.50] plt.rcParams[figure.autolayout] = True np.random.seed

  20. วิธีเพิ่ม Shared X-label และ Y-label ให้ Plot จาก Pandas Plot

    การเพิ่ม Shared Axis Labels ใน Pandas Subplots ใช้ df.plot() พร้อม subplots=True, sharex=True, sharey=True ขั้นตอนหลัก ตั้งค่าขนาดรูปและ padding สร้าง DataFrame 4 คอลัมน์ 4 แถว พล็อตด้วย kind=bar, subplots=True, layout=(2,2), sharey=True, sharex=True แสดงผลด้วย show() ตัวอย่างโค้ด import p

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:306/451  20-คอมพิวเตอร์/Page Goto:1 300 301 302 303 304 305 306 307 308 309 310 311 312