Parameter opsional fmt adalah cara mudah untuk menentukan pemformatan dasar seperti warna, penanda, dan gaya garis. Ini adalah notasi string pintasan yang dijelaskan di bagian Catatan di bawah ini Show >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses Anda dapat menggunakan properti sebagai argumen kata kunci untuk lebih mengontrol tampilan. Properti garis dan fmt dapat dicampur. Dua panggilan berikut menghasilkan hasil yang identik >>> plot(x, y, 'go--', linewidth=2, markersize=12) >>> plot(x, y, color='green', marker='o', linestyle='dashed', .. linewidth=2, markersize=12)_ Saat bertentangan dengan fmt, argumen kata kunci diutamakan Merencanakan data berlabel Ada cara mudah untuk memplot objek dengan data berlabel (mis. e. data yang dapat diakses oleh indeks >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses2). Alih-alih memberikan data dalam x dan y, Anda dapat memberikan objek dalam parameter data dan hanya memberikan label untuk x dan y >>> plot('xlabel', 'ylabel', data=obj) Semua objek yang dapat diindeks didukung. Ini bisa e. g. menjadi , an atau array numpy terstruktur Merencanakan beberapa set data Ada berbagai cara untuk memplot beberapa kumpulan data
Secara default, setiap baris diberi gaya berbeda yang ditentukan oleh 'siklus gaya'. Parameter properti fmt dan garis hanya diperlukan jika Anda menginginkan penyimpangan eksplisit dari default ini. Sebagai alternatif, Anda juga dapat mengubah siklus gaya menggunakan >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses6 (default. >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_7)Parameter . x, y seperti array atau skalar Koordinat horizontal / vertikal dari titik data. nilai x adalah opsional dan default ke >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses8 Umumnya, parameter ini adalah array 1D Mereka juga bisa berupa skalar, atau dua dimensi (dalam hal ini, kolom mewakili kumpulan data terpisah) Argumen ini tidak dapat diteruskan sebagai kata kunci fmt str, opsionalSebuah format string, mis. g. 'ro' untuk lingkaran merah. Lihat bagian Catatan untuk penjelasan lengkap tentang format string String format hanyalah singkatan untuk mengatur properti garis dasar dengan cepat. Semua ini dan lebih banyak lagi juga dapat dikontrol oleh argumen kata kunci Argumen ini tidak dapat diteruskan sebagai kata kunci data objek yang dapat diindeks, opsionalObjek dengan data berlabel. Jika diberikan, berikan nama label untuk diplot dalam x dan y Catatan Secara teknis ada sedikit ambiguitas dalam pemanggilan di mana label kedua adalah fmt yang valid. >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_9 bisa menjadi >>> plot(x, y, 'go--', linewidth=2, markersize=12) >>> plot(x, y, color='green', marker='o', linestyle='dashed', .. linewidth=2, markersize=12)0 atau >>> plot(x, y, 'go--', linewidth=2, markersize=12) >>> plot(x, y, color='green', marker='o', linestyle='dashed', .. linewidth=2, markersize=12)1. Dalam kasus seperti itu, interpretasi sebelumnya dipilih, tetapi peringatan dikeluarkan. Anda dapat menekan peringatan dengan menambahkan string format kosong >>> plot(x, y, 'go--', linewidth=2, markersize=12) >>> plot(x, y, color='green', marker='o', linestyle='dashed', .. linewidth=2, markersize=12)2Pengembalian . Daftar Daftar baris yang mewakili data yang diplot Parameter Lain . scalex, scaley bool, bawaan. BENARParameter ini menentukan apakah batas tampilan disesuaikan dengan batas data. Nilai-nilai diteruskan ke **kwargs properti, opsionalkwarg digunakan untuk menentukan properti seperti label garis (untuk legenda otomatis), lebar garis, antialiasing, warna wajah penanda. Contoh >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2') Jika Anda menentukan beberapa baris dengan satu panggilan plot, kwarg berlaku untuk semua baris tersebut. Jika objek label dapat diubah, setiap elemen digunakan sebagai label untuk setiap kumpulan data Berikut adalah daftar properti yang tersedia Properti Keterangan fungsi filter, yang mengambil array float (m, n, 3) dan nilai dpi, dan mengembalikan array (m, n, 3) dan dua offset dari sudut kiri bawah gambar skalar atau tidak ada bool atau aa bool bool Patch atau (Path, Transform) atau Tidak Ada atau c warna atau {'pantat', 'memproyeksikan', 'bulat'} atau {'mitra', 'bulat', 'bevel'} urutan pelampung (tinta hidup/mati dalam titik) atau (Tidak ada, Tidak ada) (2, N) larik atau dua larik 1D atau ds {'default', 'langkah', 'langkah-pra', 'langkah-pertengahan', 'langkah-posting'}, default. 'bawaan' {'penuh', 'kiri', 'kanan', 'bawah', 'atas', 'tidak ada'} warna atau Tidak Ada str bool obyek atau ls {'-', '--', '-. ', '. ', '', (offset, on-off-seq),. } atau lw mengambang string gaya penanda, atau atau mek warna atau mengeong mengambang atau mfc warna atau mfcalt warna atau ms mengambang Tidak ada atau int atau (int, int) atau irisan atau daftar[int] atau float atau (float, float) atau daftar[bool] bool float atau callable[[Artis, Acara], tuple[bool, dict]] tidak dikenal bool (skala. mengambang, panjang. mengambang, keacakan. mengambang) bool atau Tidak ada atau {'pantat', 'memproyeksikan', 'bulat'} atau {'mitra', 'bulat', 'bevel'} tidak dikenal str bool larik 1D larik 1D mengambang Lihat juga Plot sebar XY dengan marker dengan berbagai ukuran dan/atau warna (terkadang juga disebut bagan gelembung) Catatan Memformat String String format terdiri dari bagian untuk warna, penanda, dan garis fmt = '[marker][line][color]' Masing-masing adalah opsional. Jika tidak disediakan, nilai dari siklus gaya akan digunakan. Pengecualian. Jika >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')_0 diberikan, tetapi tidak ada >>> x = [1, 2, 3] >>> y = np.array([[1, 2], [3, 4], [5, 6]]) >>> plot(x, y)2, data akan berupa garis tanpa penanda Kombinasi lain seperti >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')_2 juga didukung, tetapi perhatikan bahwa penguraiannya mungkin ambigu Penanda karakter keterangan >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')_3 penanda titik >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')4 penanda piksel >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')5 penanda lingkaran >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')6 penanda segitiga_bawah >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')7 penanda segitiga_atas >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')8 penanda segitiga_kiri >>> plot([1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2) >>> plot([1, 2, 3], [1, 4, 9], 'rs', label='line 2')_9 penanda segitiga_kanan fmt = '[marker][line][color]'_0 penanda tri_down fmt = '[marker][line][color]'_1 penanda tri_up fmt = '[marker][line][color]'_2 penanda tri_kiri fmt = '[marker][line][color]'_3 penanda tri_right fmt = '[marker][line][color]'_4 penanda segi delapan fmt = '[marker][line][color]'_5 penanda persegi fmt = '[marker][line][color]'_6 penanda segi lima fmt = '[marker][line][color]'_7 plus (diisi) penanda fmt = '[marker][line][color]'_8 penanda bintang fmt = '[marker][line][color]'_9 penanda segi enam >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_00 penanda segi enam >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_01 ditambah penanda >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_02 penanda x >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_03 penanda x (diisi). >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_04 penanda berlian >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_05 penanda berlian_tipis >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_06 penanda vline >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_07 penanda hline Gaya Garis karakter keterangan >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_08 gaya garis padat >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_09 gaya garis putus-putus >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_10 gaya garis putus-putus >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_11 gaya garis putus-putus Contoh format string >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses0 Warna Singkatan warna yang didukung adalah kode satu huruf karakter warna >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_12 biru >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_13 hijau >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_14 merah >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_15 cyan >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_16 magenta >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_17 kuning >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_18 hitam >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_19 putih dan >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_20 warna yang mengindeks ke dalam siklus properti default Jika warna adalah satu-satunya bagian dari string format, Anda juga dapat menggunakan spesifikasi apa pun, mis. g. nama lengkap ( >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses_22) atau string hex ( >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses23) Bagaimana Anda menggambar plot garis dengan Python?Langkah-Langkah Membuat Diagram Garis dengan Python menggunakan Matplotlib . Langkah 1. Instal paket Matplotlib. . Langkah 2. Kumpulkan data untuk bagan Garis. . Langkah 3. Tangkap data dengan Python. . Langkah 4. Plot grafik Garis dengan Python menggunakan Matplotlib Bagaimana Anda memplot garis lurus pada sebar plot di Python?Buat figur baru, atau aktifkan figur yang sudah ada dengan ukuran figur (4, 3), menggunakan metode figure() Tambahkan sumbu ke gambar saat ini dan jadikan sumbu saat ini, buat x menggunakan plt. . Gambar titik pencar menggunakan metode scatter() Gambar garis menggunakan kapak. . Tetapkan label sumbu X menggunakan plt. . Atur label sumbu Y menggunakan plt Bagaimana Anda memplot koordinat dengan Python?Untuk memplot koordinat dengan Python, kami menggunakan modul pyplot dari perpustakaan matplotlib . Modul Pyplot memiliki metode plot() untuk memplot koordinat.
Bagaimana Anda melakukan plot berdampingan dengan Python?Membuat poin x, y1, y2 menggunakan numpy Dengan nrows = 1, ncols = 2, index = 1, tambahkan subplot ke gambar saat ini, menggunakan metode subplot() Plot garis menggunakan titik x dan y1, menggunakan metode plot() Siapkan judul, label untuk sumbu X dan Y untuk Gambar 1, menggunakan plt |