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
>>> 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 plusses 2). 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
Cara yang paling mudah adalah menelepon beberapa kali. Contoh
>>> plot(x1, y1, 'bo') >>> plot(x2, y2, 'go') _
Jika x dan/atau y adalah array 2D, kumpulan data terpisah akan digambar untuk setiap kolom. Jika x dan y adalah 2D, keduanya harus memiliki bentuk yang sama. Jika hanya salah satu dari mereka adalah 2D dengan bentuk (N, m) yang lain harus memiliki panjang N dan akan digunakan untuk setiap kumpulan data m
Contoh
>>> x = [1, 2, 3] >>> y = np.array([[1, 2], [3, 4], [5, 6]]) >>> plot(x, y)
setara dengan
>>> for col in range(y.shape[1]): .. plot(x, y[:, col]) _
Cara ketiga adalah menentukan beberapa set grup [x], y, [fmt].
>>> plot(x1, y1, 'g^', x2, y2, 'g-')
Dalam hal ini, argumen kata kunci tambahan berlaku untuk semua kumpulan data. Sintaks ini juga tidak dapat digabungkan dengan parameter 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 plusses 6 (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 skalarKoordinat 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 plusses 8
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) 2
Pengembalian . DaftarDaftar 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 plusses 0
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 plusses 23)