Hướng dẫn how do you plot multiple arrays in one plot python? - làm thế nào để bạn vẽ nhiều mảng trong một bản python?

Tài liệu cho plt.subplots() (ở đây) chỉ định rằng nó có một đối số nrowsncols và trả về một đối tượng fig và một mảng các đối tượng ax. Đối với trường hợp của bạn, điều này sẽ như thế này:

fig, axs = plt.subplots(3, 4)

axs hiện chứa một mảng 2D chứa đầy các đối tượng ax mà bạn có thể sử dụng để vẽ đồ thị những thứ khác nhau, ví dụ: axs[0,1].plot([1,2],[3,4,]) sẽ vẽ một cái gì đó ở hàng thứ nhất, cột thứ hai.

Nếu bạn muốn xóa một đối tượng ax cụ thể, bạn có thể làm điều đó với

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
1, ví dụ:
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
2.

Đối với

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
3, nó hoạt động chính xác theo cách tương tự như
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
4: Chọn Axe bạn muốn và gọi
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
5 trên đó.

Một ví dụ đầy đủ với dữ liệu hình ảnh mô phỏng cho trường hợp của bạn sẽ là:

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()

Với kết quả:

Hướng dẫn how do you plot multiple arrays in one plot python? - làm thế nào để bạn vẽ nhiều mảng trong một bản python?

Trong bài viết này, chúng tôi sẽ học cách vẽ nhiều dòng bằng cách sử dụng matplotlib trong Python. Hãy để thảo luận về một số khái niệm:

  • Matplotlib: Matplotlib là một thư viện trực quan tuyệt vời trong Python cho các lô 2D của mảng. Matplotlib là một thư viện trực quan hóa dữ liệu đa nền tảng được xây dựng trên các mảng numpy và được thiết kế để hoạt động với ngăn xếp Scipy rộng hơn. Nó được giới thiệu bởi John Hunter vào năm 2002. Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002.
  • Biểu đồ dòng: Các sơ đồ dòng có thể được tạo trong Python với thư viện pyplot Matplotlib. Để xây dựng một biểu đồ dòng, đầu tiên nhập matplotlib. Đó là một quy ước tiêu chuẩn để nhập thư viện pyplot matplotlib từ PLT. Bí danh PLT sẽ quen thuộc với các lập trình viên Python khác. Line plots can be created in Python with Matplotlib’s pyplot library. To build a line plot, first import Matplotlib. It is a standard convention to import Matplotlib’s pyplot library as plt. The plt alias will be familiar to other Python programmers.

Ở đây chúng tôi sẽ thảo luận về một số ví dụ để vẽ một dòng hoặc nhiều dòng với các tính năng khác nhau. Để thực hiện công việc như vậy, chúng tôi phải làm theo các bước được đưa ra dưới đây:

  • Nhập thư viện.
  • Tạo dữ liệu.
  • Vẽ các dòng trên dữ liệu.

Vẽ một đường ngang duy nhất

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường ngang với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu cho hai chiều (x và y) và cuối cùng là biểu đồ dòng. Để tạo một đường ngang, chúng ta phải thay đổi giá trị của trục x liên tục bằng cách lấy trục y là hằng số.

Python3

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
6
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
7

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
8
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()1plt.subplots()2223__2222225252222272722222929

nrows1

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()5__2222252522222525__222252522222525

ncols4

ncols5

Output:

Vẽ một đường thẳng đứng

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường thẳng đứng với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu với hai chiều (x và y) và cuối cùng là biểu đồ dòng. Để tạo một đường thẳng đứng, chúng ta phải thay đổi giá trị của trục y liên tục bằng cách lấy trục x là hằng số. Vì vậy, chúng tôi thay đổi các trục để có được một đường thẳng đứng.

Python3

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
6
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
7

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
8
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()1plt.subplots()2223__2222225252222272722222929

nrows1

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()5__2222252522222525__222252522222525

axs4

ncols5

Output:

Hướng dẫn how do you plot multiple arrays in one plot python? - làm thế nào để bạn vẽ nhiều mảng trong một bản python?

Vẽ một đường thẳng đứng

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường thẳng đứng với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu với hai chiều (x và y) và cuối cùng là biểu đồ dòng. Để tạo một đường thẳng đứng, chúng ta phải thay đổi giá trị của trục y liên tục bằng cách lấy trục x là hằng số. Vì vậy, chúng tôi thay đổi các trục để có được một đường thẳng đứng.

Python3

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
6
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
7

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
8
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()1plt.subplots()2223__2222225252222272722222929

nrows1

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()5__2222252522222525__222252522222525

Vẽ một đường thẳng đứng

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường thẳng đứng với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu với hai chiều (x và y) và cuối cùng là biểu đồ dòng. Để tạo một đường thẳng đứng, chúng ta phải thay đổi giá trị của trục y liên tục bằng cách lấy trục x là hằng số. Vì vậy, chúng tôi thay đổi các trục để có được một đường thẳng đứng.

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
12

ncols5

Output:

Vẽ một đường ngang và đường thẳng đứng & nbsp;

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường ngang và một đường thẳng đứng cả trong một biểu đồ với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu với hai chiều (x và y) và cuối cùng vẽ đường dây liên quan đến kích thước. Vì vậy, trong ví dụ này, chúng tôi hợp nhất cả hai biểu đồ ở trên để tạo cả hai dòng với nhau trong một biểu đồ.

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
04
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
06
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
07

  • import numpy as np
    import matplotlib.pyplot as plt
    
    fig, axs = plt.subplots(3, 4)
    images = [np.array([[1,2],[3,4]]) for _ in range(10)]
    for i, ax in enumerate(axs.flatten()):
        if i < len(images):
            ax.imshow(images[i])
        else:
            ax.remove()
    plt.show()
    
    08
    import numpy as np
    import matplotlib.pyplot as plt
    
    fig, axs = plt.subplots(3, 4)
    images = [np.array([[1,2],[3,4]]) for _ in range(10)]
    for i, ax in enumerate(axs.flatten()):
        if i < len(images):
            ax.imshow(images[i])
        else:
            ax.remove()
    plt.show()
    
    9
    import numpy as np
    import matplotlib.pyplot as plt
    
    fig, axs = plt.subplots(3, 4)
    images = [np.array([[1,2],[3,4]]) for _ in range(10)]
    for i, ax in enumerate(axs.flatten()):
        if i < len(images):
            ax.imshow(images[i])
        else:
            ax.remove()
    plt.show()
    
    10
    import numpy as np
    import matplotlib.pyplot as plt
    
    fig, axs = plt.subplots(3, 4)
    images = [np.array([[1,2],[3,4]]) for _ in range(10)]
    for i, ax in enumerate(axs.flatten()):
        if i < len(images):
            ax.imshow(images[i])
        else:
            ax.remove()
    plt.show()
    
    07
  • Vẽ nhiều dòng
  • Trong ví dụ này, chúng tôi sẽ học cách vẽ nhiều dòng với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu có hai chiều (x và y) và cuối cùng vẽ các dòng là các kích thước và hàm khác nhau trên cùng một dữ liệu.
  • Để vẽ nhiều dòng, chúng tôi sẽ sử dụng các chức năng khác nhau như sau:

Python3

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
6
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
7

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
8
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()1plt.subplots()2223__2222225252222272722222929

nrows1

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()5__2222252522222525__222252522222525

Vẽ một đường thẳng đứng

Vẽ một đường thẳng đứng

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường thẳng đứng với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu với hai chiều (x và y) và cuối cùng là biểu đồ dòng. Để tạo một đường thẳng đứng, chúng ta phải thay đổi giá trị của trục y liên tục bằng cách lấy trục x là hằng số. Vì vậy, chúng tôi thay đổi các trục để có được một đường thẳng đứng.

Vẽ một đường ngang và đường thẳng đứng & nbsp;

Trong ví dụ này, chúng ta sẽ học cách vẽ một đường ngang và một đường thẳng đứng cả trong một biểu đồ với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu với hai chiều (x và y) và cuối cùng vẽ đường dây liên quan đến kích thước. Vì vậy, trong ví dụ này, chúng tôi hợp nhất cả hai biểu đồ ở trên để tạo cả hai dòng với nhau trong một biểu đồ.

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
12

ncols5

Output:

import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots(3, 4) images = [np.array([[1,2],[3,4]]) for _ in range(10)] for i, ax in enumerate(axs.flatten()): if i < len(images): ax.imshow(images[i]) else: ax.remove() plt.show() 04import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots(3, 4) images = [np.array([[1,2],[3,4]]) for _ in range(10)] for i, ax in enumerate(axs.flatten()): if i < len(images): ax.imshow(images[i]) else: ax.remove() plt.show() 9 import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots(3, 4) images = [np.array([[1,2],[3,4]]) for _ in range(10)] for i, ax in enumerate(axs.flatten()): if i < len(images): ax.imshow(images[i]) else: ax.remove() plt.show() 06import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots(3, 4) images = [np.array([[1,2],[3,4]]) for _ in range(10)] for i, ax in enumerate(axs.flatten()): if i < len(images): ax.imshow(images[i]) else: ax.remove() plt.show() 07

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
08
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
10
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
07

Vẽ nhiều dòng

  • Trong ví dụ này, chúng tôi sẽ học cách vẽ nhiều dòng với sự trợ giúp của matplotlib. Ở đây chúng tôi sẽ sử dụng hai danh sách làm dữ liệu có hai chiều (x và y) và cuối cùng vẽ các dòng là các kích thước và hàm khác nhau trên cùng một dữ liệu.       : dashed
  • Để vẽ nhiều dòng, chúng tôi sẽ sử dụng các chức năng khác nhau như sau:      : double dashed
  • y = x     : dashed-dotted
  • x = y       : dotted

Python3

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
6
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
7

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
8
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()1plt.subplots()2223__2222225252222272722222929

nrows1

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0plt.subplots()5__2222252522222525__222252522222525

nrows1

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9 plt.subplots()0
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
25__222225125____22225125__222225

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
04
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
06
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
95
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9__197

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
08
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
10
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
95
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9plt.subplots()04__107

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
52
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
54
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
95
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9plt.subplots()11
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
07

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
56
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
58
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
95
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
9plt.subplots()18
import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
07

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 4)
images = [np.array([[1,2],[3,4]]) for _ in range(10)]
for i, ax in enumerate(axs.flatten()):
    if i < len(images):
        ax.imshow(images[i])
    else:
        ax.remove()
plt.show()
12

ncols5

Output:


Làm thế nào để bạn vẽ hai mảng trong Python?

Để vẽ đồ thị trong Python, chúng tôi sẽ sử dụng thư viện matplotlib.Matplotlib được sử dụng cùng với dữ liệu numpy để vẽ bất kỳ loại đồ thị nào.Từ matplotlib, chúng tôi sử dụng hàm cụ thể, tức là pyplot (), được sử dụng để vẽ dữ liệu hai chiều.use the Matplotlib library. Matplotlib is used along with NumPy data to plot any type of graph. From matplotlib we use the specific function i.e. pyplot(), which is used to plot two-dimensional data.

Làm thế nào để bạn vẽ nhiều dữ liệu trong một biểu đồ trong Python?

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.Tham số: NROW, NCOLS: Chúng cung cấp số lượng hàng và cột tương ứng.. Parameters: nrows, ncols: These gives the number of rows and columns respectively.

Làm thế nào để bạn vẽ nhiều danh sách trong Python?

Biểu đồ dòng: Các sơ đồ dòng có thể được tạo trong Python với thư viện pyplot của Matplotlib.Để xây dựng một biểu đồ dòng, đầu tiên nhập matplotlib.Đó là một quy ước tiêu chuẩn để nhập thư viện pyplot của matplotlib như plt ...
Nhập thư viện ..
Tạo dữ liệu ..
Vẽ các dòng trên dữ liệu ..

Chúng ta có thể vẽ hai danh sách trong Python không?

Bạn nên sử dụng plt.plot hai lần để vẽ hai dòng.use plt. plot twice to plot two lines.