Điều kiện tiên quyết: matplotlib: Matplotlib
Trong matplotlib, chúng ta có thể vẽ nhiều biểu đồ trong một lô theo hai cách. Một là bằng cách sử dụng hàm Subplot [] và các hàm khác bằng cách chồng chất của biểu đồ thứ hai trên i.e đầu tiên, tất cả các biểu đồ sẽ xuất hiện trên cùng một lô. Chúng tôi sẽ xem xét cả hai cách từng người một.
Nhiều sơ đồ sử dụng hàm Subplot []
Hàm Subplot [] là hàm trình bao bọc cho phép lập trình viên vẽ nhiều hơn một biểu đồ trong một hình bằng cách gọi nó một lần.
Cú pháp: matplotlib.pyplot.subplots [nrows = 1, ncols = 1, sharex = false, sharey = false, squeeze = true, subplot_kw = none matplotlib.pyplot.subplots[nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw]
Parameters:
- NROWS, NCOLS: & NBSP; Chúng cung cấp số lượng hàng và cột & nbsp; tương ứng. Ngoài ra, phải lưu ý rằng cả hai tham số này đều là tùy chọn và giá trị mặc định là 1. These gives the number of rows and columns respectively. Also, it must be noted that both these parameters are optional and the default value is 1.
- chia sẻ, chia sẻ: & nbsp; Các tham số này chỉ định về các thuộc tính được chia sẻ giữa các giá trị A và Y.Possible cho chúng có thể là, hàng, col, không có hoặc giá trị mặc định là sai. These parameters specify about the properties that are shared among a and y axis.Possible values for them can be, row, col, none or default value which is False.
- Squeeze: & nbsp; Tham số này là một giá trị boolean được chỉ định, yêu cầu lập trình viên có nên vắt ra hay không, có nghĩa là loại bỏ kích thước phụ khỏi mảng. Nó có một giá trị mặc định sai.This parameter is a boolean value specified, which asks the programmer whether to squeeze out, meaning remove the extra dimension from the array. It has a default value False.
- subplot_kw: Các tham số này cho phép chúng tôi thêm các từ khóa vào mỗi subplot và giá trị mặc định của nó là không có.This parameters allow us to add keywords to each subplot and its default value is None.
- GridSpec_kw: Điều này cho phép chúng tôi thêm lưới trên mỗi subplot và có giá trị mặc định là không có.This allows us to add grids on each subplot and has a default value of None.
- ** FIG_KW: Điều này cho phép chúng tôi chuyển bất kỳ đối số từ khóa bổ sung nào khác cho cuộc gọi chức năng và có giá trị mặc định là không có.This allows us to pass any other additional keyword argument to the function call and has a default value of None.
Thí dụ :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
import
math
X
=
matplotlib.pyplot as plt
6=
matplotlib.pyplot as plt
8
matplotlib.pyplot as plt
9=
import
1
import
2=
import
4
import
5=
import
7
import
8=
numpy as np
0__12
numpy as np
50
matplotlib.pyplot as plt
30
numpy as np
9
numpy as np
50
matplotlib.pyplot as plt
30
import
4import
5matplotlib.pyplot as plt
5
numpy as np
50
matplotlib.pyplot as plt
3math
0math
1
Các
numpy as np
5math
0matplotlib.pyplot as plt
30
X
3
numpy as np
5math
0matplotlib.pyplot as plt
30
import
4X
9matplotlib.pyplot as plt
5
numpy as np
5math
0matplotlib.pyplot as plt
3math
0=
5
numpy as np
5math
0matplotlib.pyplot as plt
3math
0import
4np.arange[
1matplotlib.pyplot as plt
5
np.arange[
3
Đầu ra
Nhiều sơ đồ sử dụng hàm Subplot []
Trong matplotlib, có một hàm khác rất giống với subplot là subplot2grid []. Nó gần giống như hàm Subplot nhưng cung cấp sự linh hoạt hơn để sắp xếp các đối tượng cốt truyện theo nhu cầu của lập trình viên.
Hàm này được viết như sau:
Cú pháp: matplotlib.pyplot.subplot2grid [hình dạng, loc, rowspan = 1, colspan = 1, fig = none, ** kwargs]matplotlib.pyplot.subplot2grid[shape, loc, rowspan=1, colspan=1, fig=None, **kwargs]
Parameter:
- Tham số Shapethis là một chuỗi gồm hai giá trị số nguyên cho biết hình dạng của lưới mà chúng ta cần đặt các trục. Mục đầu tiên là cho hàng, trong khi mục thứ hai là dành cho cột.
This parameter is a sequence of two integer values which tells the shape of the grid for which we need to place the axes. The first entry is for row, whereas the second entry is for column.- Tham số hình dạng locus, thậm chí IOC là một chuỗi gồm 2 giá trị số nguyên, trong đó mục đầu tiên vẫn còn cho hàng và thứ hai là để cột đặt trục trong lưới.
Like shape parameter, even Ioc is a sequence of 2 integer values, where first entry remains for the row and the second is for column to place axis within grid.- Tham số Rowspanthis lấy giá trị nguyên và số cho biết số lượng hàng cho trục kéo dài hoặc tăng về phía bên phải.
This parameter takes integer value and the number which indicates the number of rows for the axis to span to or increase towards right side.- Tham số colspanthis lấy giá trị số nguyên và số cho biết số lượng cột cho trục kéo dài hoặc tăng độ dài xuống.
This parameter takes integer value and the number which indicates the number of columns for the axis to span to or increase the length downwards.- Figthis là một tham số tùy chọn và đưa hình để đặt trục vào. Nó mặc định là hình hiện tại.
This is an optional parameter and takes Figure to place axis in. It defaults to current figure.- ** kwargsthis cho phép chúng tôi chuyển bất kỳ đối số từ khóa bổ sung nào khác cho cuộc gọi hàm và có giá trị mặc định là không có.
This allows us to pass any other additional keyword argument to the function call and has a default value of None.
Thí dụ :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
import
math
X
=
matplotlib.pyplot as plt
6=
matplotlib.pyplot as plt
8
matplotlib.pyplot as plt
9=
import
1
import
2=
import
4
matplotlib.pyplot as plt
42matplotlib.pyplot as plt
1matplotlib.pyplot as plt
1matplotlib.pyplot as plt
45matplotlib.pyplot as plt
5
matplotlib.pyplot as plt
47matplotlib.pyplot as plt
48matplotlib.pyplot as plt
5
matplotlib.pyplot as plt
50
matplotlib.pyplot as plt
51matplotlib.pyplot as plt
52matplotlib.pyplot as plt
5
matplotlib.pyplot as plt
54matplotlib.pyplot as plt
1matplotlib.pyplot as plt
56
matplotlib.pyplot as plt
57matplotlib.pyplot as plt
58matplotlib.pyplot as plt
5
matplotlib.pyplot as plt
60
np.arange[
3
Đầu ra
Nhiều sơ đồ sử dụng hàm Subplot []
Trong matplotlib, có một hàm khác rất giống với subplot là subplot2grid []. Nó gần giống như hàm Subplot nhưng cung cấp sự linh hoạt hơn để sắp xếp các đối tượng cốt truyện theo nhu cầu của lập trình viên.
Hàm này được viết như sau:
Thí dụ :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
import
math
X
=
matplotlib.pyplot as plt
78=
matplotlib.pyplot as plt
8
matplotlib.pyplot as plt
81=
import
1
Các
matplotlib.pyplot as plt
91=
matplotlib.pyplot as plt
93matplotlib.pyplot as plt
87=
matplotlib.pyplot as plt
96matplotlib.pyplot as plt
5
matplotlib.pyplot as plt
98matplotlib.pyplot as plt
99matplotlib.pyplot as plt
5
import
01import
02matplotlib.pyplot as plt
5
import
04import
05matplotlib.pyplot as plt
5
import
07
np.arange[
3
Đầu ra
đường cong chức năng sin và cosine trong một biểu đồ