Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. วิธีปรับขนาดแกนใน Mplot3d (Matplotlib 3D)

    ตั้งค่าช่วงแกน x, y, z ในกราฟ 3D ใช้ set_xlim3d, set_ylim3d, set_zlim3d ขั้นตอน สร้าง figure ด้วย figure() สร้าง axes 3D ด้วย Axes3D() ปรับแกน X ด้วย set_xlim3d() ปรับแกน Y ด้วย set_ylim3d() ปรับแกน Z ด้วย set_zlim3d() แสดงด้วย show() ตัวอย่างโค้ด from mpl_toolkits.mplot3d import Axes3D from ma

  2. วิธีตั้งค่าสีให้ Rectangle ใน Matplotlib

    กำหนดสีขอบและสีพื้นของสี่เหลี่ยม ใช้พารามิเตอร์ edgecolor, facecolor, linewidth ใน Rectangle() ขั้นตอน สร้าง figure ด้วย figure() เพิ่ม axes ด้วย add_subplot() สร้าง rectangle ด้วยจุดลوك anchor, ความกว้าง, ความสูง เพิ่ม rectangle patch ลง plot ตั้งค่าขอบเขตแกน x, y ด้วย xlim() และ ylim() แสดงด้วย

  3. วิธีหาจุดกึ่งกลางของชุดจุดใน Python

    คำนวณ centroid ของชุดจุด หาจุดกึ่งกลางโดยเฉลี่ยค่า x และค่า y แยกกัน ขั้นตอน สร้าง list ข้อมูล x และ y วาดจุดด้วย plot() คำนวณจุดกึ่งกลาง: (sum(x)/len(x), sum(y)/len(y)) วาดจุดกึ่งกลางบนกราฟ เพิ่ม annotation ป้ายกำกับจุดกึ่งกลาง แสดงด้วย show() ตัวอย่างโค้ด , connectionstyle=arc3,rad=0)) plt.s

  4. วิธีเพิ่มข้อความภายในสี่เหลี่ยมผืนผ้าใน Matplotlib

    วางข้อความตรงกลางสี่เหลี่ยมผืนผ้า ใช้ annotate() วางข้อความที่จุดกึ่งกลางของ rectangle ขั้นตอน สร้าง figure ด้วย figure() เพิ่ม subplot สร้าง rectangle ด้วยคลาส Rectangle() เพิ่ม rectangle patch ลง plot คำนวณจุดกึ่งกลาง cx, cy ของ rectangle ใช้ annotate() วางข้อความตรงกลาง จำกัดแกน x, y ให้เห็นสี

  5. วิธีวาดกราฟ 3D ด้วย Python Matplotlib

    สร้างกราฟ 3 มิติพื้นฐาน ใช้ mpl_toolkits.mplot3d และ scatter3D ขั้นตอน สร้าง figure ด้วย figure() ดึง axes 3D object สร้าง list x, y, z สำหรับจุดข้อมูล เพิ่ม 3D scatter points ด้วย scatter3D() markersize=150, marker=diamond แสดงด้วย show() ตัวอย่างโค้ด from mpl_toolkits.mplot3d import Axes3D fr

  6. วิธีใช้ sharex กับ subplot2grid ใน Matplotlib

    แบ่งปันแกน x ระหว่าง subplot2grid ใช้พารามิเตอร์ sharex ใน subplot2grid ที่สอง ขั้นตอน สร้างข้อมูลสุ่ม t, x, y1, y2 ด้วย NumPy สร้าง figure ด้วย figure() สร้าง subplot แรกที่ตำแหน่งเฉพาะ colspan=3, rowspan=2 สร้าง subplot ที่สอง sharex=ax1 (subplot แรก) วาดกราฟด้วย t, y1 และ y2 ปรับ padding ด้วย

  7. วิธีให้ sns.clustermap ใช้เมทริกซ์ระยะทางที่คำนวณแล้วใน Matplotlib

    ใช้ clustermap กับข้อมูลที่มีเมทริกซ์ระยะทางสำเร็จรูป โหลดชุดข้อมูลตัวอย่าง แล้ววาด hierarchically-clustered heatmap ขั้นตอน ตั้งค่า theme หลายพารามิเตอร์พร้อมกัน โหลดข้อมูลตัวอย่างจากออนไลน์ แยกคอลัมน์ species ด้วย pop() วาด heatmap แบบ hierarchical clustering ด้วย clustermap() แสดงด้วย show()

  8. การวาดกราฟ numpy datetime64 ด้วย Matplotlib

    วาดกราฟอนุกรมเวลา (time series) ด้วย datetime64 ใช้ NumPy สร้างอาร์เรย์ datetime64 และวาดกราฟ ขั้นตอน สร้างจุดข้อมูล x, y ด้วย NumPy วาดกราฟด้วย plot() แสดงด้วย show() ตัวอย่างโค้ด import matplotlib.pyplot as plt import datetime import numpy as np plt.rcParams[figure.figsize] = [7.00, 3.50] pl

  9. การส่งออกไฟล์ SVG จาก figure ใน Matplotlib

    บันทึก figure เป็นไฟล์ SVG ใช้เมธอด savefig() บันทึกเป็นไฟล์ .svg ขั้นตอน ตั้งค่าขนาด figure และปรับ padding สร้าง figure และ subplots สร้างข้อมูล x, y สุ่มด้วย NumPy วาดกราฟด้วย plot() บันทึกไฟล์ .svg ด้วย savefig() ตัวอย่างโค้ด import numpy as np from matplotlib import pyplot as plt plt.rcPa

  10. วิธีสร้าง histogram จากรายการข้อมูลใน Matplotlib

    สร้าง histogram จาก list ข้อมูล ใช้เมธอด hist() วาด histogram จากข้อมูล list ขั้นตอน สร้าง list ข้อมูล (x data points) วาด histogram ด้วย hist() แสดงด้วย show() ตัวอย่างโค้ด from matplotlib import pyplot as plt plt.rcParams[figure.figsize] = [7.00, 3.50] plt.rcParams[figure.autolayout] = True

  11. วิธีแปลงตัวเลขเป็นสเกลสีใน Matplotlib

    แมปค่าตัวเลขเป็นสีด้วย colormap ใช้ Normalize และ ScalarMappable แปลงค่าตัวเลขเป็นสี ขั้นตอน สร้างจุดข้อมูล x, y, c ด้วย NumPy แปลงเป็น Pandas DataFrame สร้าง figure ด้วย subplots() ดึง colormap hot ใช้ Normalize() ปรับค่าให้เป็น 0-1 วาด scatter พร้อมสีจาก colormap ที่ normalize แล้ว ตั้งค่า xtic

  12. วิธีจัดตำแหน่งและจัดแนว legend ของ figure ใน Matplotlib

    จัดตำแหน่งและจัดแนว legend ใช้ bbox_to_anchor กำหนดตำแหน่ง และ ncol สำหรับการจัดแนวแนวนอน ขั้นตอน วาด line1 และ line2 ด้วย plot() วาง legend บน figure ใช้ bbox_to_anchor กำหนดตำแหน่ง และ ncol=2 จัดแนวแนวนอน แสดงด้วย show() ตัวอย่างโค้ด from matplotlib import pyplot as plt plt.rcParams[figure.f

  13. วิธีใช้ matplotlib.animate สร้างแอนิเมชัน contour plot ใน Python

    สร้างแอนิเมชัน contour plot ใช้ FuncAnimation อัปเดต contour plot ซ้ำๆ ขั้นตอน สร้างข้อมูลสุ่มขนาด 10x10x8 สร้าง figure และ subplots ด้วย subplots() ใช้ FuncAnimation() เรียกฟังก์ชัน animate ซ้ำ กำหนดฟังก์ชัน animate อัปเดตค่า contour แสดงด้วย show() ตัวอย่างโค้ด import numpy as np import matpl

  14. การสร้างกราฟ 3D จากอาร์เรย์ NumPy 3 มิติใน Matplotlib

    สร้าง 3D plot จากอาร์เรย์ NumPy 3 มิติ สร้างอาร์เรย์ 3 มิติ แล้วแยกจุด x, y, z มาวาด scatter plot สร้าง figure ด้วย figure() เพิ่ม axes 3D ด้วย add_subplot(projection=3d) สร้างข้อมูลสุ่ม size=(3, 3, 3) แยก x, y, z จากอาร์เรย์ 3D วาด 3D scattered points แสดงด้วย show() ตัวอย่างโค้ด import numpy

  15. การวาดจุดบนผิวทรงกลมด้วย Matplotlib ใน Python

    วาดจุดบนพื้นผิวทรงกลม ใช้เมธอด plot_surface() วาดทรงกลม ขั้นตอน สร้าง figure ด้วย figure() เพิ่ม subplot 3D ด้วย add_subplot(projection=3d) กำหนดตัวแปร r (รัศมี) คำนวณ theta และจุด x, y, z ด้วย NumPy วาดผิวด้วย plot_surface() แสดงด้วย show() ตัวอย่างโค้ด import matplotlib.pyplot as plt import n

  16. วิธีทำ heatmap ให้เป็นสี่เหลี่ยมจัตุรัสใน Seaborn FacetGrid ด้วย Matplotlib

    ทำให้ heatmap เป็นสี่เหลี่ยมจัตุรัสใน FacetGrid ใช้เมธอด heatmap() พร้อมข้อมูลสุ่ม 10x10 ขั้นตอน สร้างข้อมูลสุ่มขนาด 10x10 ค่า -1 ถึง 10 วาด heatmap ด้วย heatmap() พร้อม colormap twilight_r แสดงด้วย show() ตัวอย่างโค้ด import numpy as np import seaborn as sn import matplotlib.pyplot as plt plt

  17. การวาง contourf plot และ surface_plot ชั้นกันใน Matplotlib

    ซ้อน contourf และ surface plot แบบ 3D วาด contour plot และ surface plot บน axes 3D เดียวกัน ขั้นตอน กำหนดตัวแปร delta, xrange, yrange, x, y ด้วย NumPy สร้าง figure ด้วย figure() ดึง axes 3D ด้วย projection=3d สร้าง 3D contour plot ด้วยข้อมูล x, y วาด surface plot ด้วยข้อมูล x, y แสดงด้วย show()

  18. การหมุนข้อความแกนสำหรับแต่ละ subplot ใน Matplotlib

    หมุนข้อความแกนในแต่ละ subplot ใช้ text พร้อมพารามิเตอร์ rotation เพื่อหมุนข้อความในแต่ละ subplot ขั้นตอน สร้าง figure ใหม่ เพิ่ม axes ด้วย add_subplot() ปรับ layout ด้วย subplots_adjust() เพิ่ม suptitle ด้วย suptitle() ตั้งค่า title, xlabel, ylabel สร้างแกนพร้อมพิกัด เพิ่มข้อความพร้อม fontsize, f

  19. วิธาดึงอินสแตนซ์ colorbar จาก figure ใน Matplotlib

    ดึง colorbar instance จาก figure ใช้ object scalar mappable จาก imshow() เพื่อสร้างและดึง colorbar instance ขั้นตอน สร้างข้อมูลสุ่มขนาด 10x10 ค่า -1 ถึง 1 ใช้ imshow() แสดงข้อมูลเป็นภาพ สร้าง colorbar สำหรับ ScalarMappable instance ด้วย object จาก imshow() แสดงด้วย show() ตัวอย่างโค้ด import nu

  20. วิธีปิดหน้าต่าง pyplot ทั้งหมดใน Matplotlib

    คำสั่งปิด figure windows ต่างๆ plt.figure().close(): ปิดหน้าต่าง figure close() ปิด figure ปัจจุบัน close(h) โดย h เป็น Figure instance ปิด figure นั้น close(num) ปิด figure ที่มี number=num close(name) โดย name เป็น string ปิด figure ที่มี label นั้น close(all) ปิดหน้าต่าง figure ทั้งหมด ตัวอย่

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:276/451  20-คอมพิวเตอร์/Page Goto:1 270 271 272 273 274 275 276 277 278 279 280 281 282