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

Tôi có một danh sách raws các mảng mà tôi muốn vẽ trong máy tính xách tay Ipython. Đây là mã tôi đang cố gắng để làm việc:

fig, axes = subplots(len(raws),1, sharex=True, tight_layout=True, figsize=(12, 6), dpi=72)
for r in range(len(raws)):
    axes[r].plot(raws)

Tôi đã bị mất hàng giờ nếu không phải là ngày cố gắng tìm ra cách lập chỉ mục danh sách raws, sao cho tôi có thể vẽ từng mảng MXN trên trục riêng của nó trong đó n là số điểm thời gian, tức là, trục x và m là Số lượng hàm chuỗi thời gian được lấy mẫu tại mỗi điểm.

Khi tôi viết mã:

for r in range(len(raws)):
        axes[r].plot(raws[r])

Tôi nhận được một giá trịerror: Đặt một phần tử mảng với một chuỗi.

Cho thông tin của bạn:

    len(raws) = 2
    type(raws) = 'list'
    np.shape(raws[0][0]) = (306, 10001)
    raws = 
[(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
          1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
       [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
         -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
       [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
         -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
       ..., 
       [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
          4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
       [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
          3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
       [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
          7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
         -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
       [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
         -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
       [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
          2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
       ..., 
       [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
         -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
       [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
          7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
       [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
         -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]


Sơ đồ các điểm dữ liệu x và y, với màu đỏ ..

  • Để hiển thị hình, sử dụng phương thức show () ..
  • Làm thế nào để bạn truy cập một mảng bên trong một mảng trong Python?x and y, using numpy.
  • Một mảng trong Python được sử dụng để lưu trữ nhiều giá trị hoặc mục hoặc các phần tử cùng loại trong một biến duy nhất. Chúng ta có thể truy cập các phần tử của một mảng bằng toán tử chỉ mục []. Tất cả những gì bạn cần làm để truy cập một yếu tố cụ thể là gọi cho mảng bạn đã tạo.title() method.
  • Để vẽ một mảng trong Python, chúng ta có thể thực hiện các bước sau -x and y data points, with red color.
  • Đặt kích thước hình và điều chỉnh phần đệm giữa và xung quanh các ô con.show() method.

Tạo hai mảng, x và y, sử dụng numpy.

Đặt tiêu đề của đường cong bằng phương thức Tiêu đề ().

Vẽ các điểm dữ liệu X và Y, với màu đỏ.

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

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

Để hiển thị hình, sử dụng phương thức show ().

  • Thí dụ
  • import numpy as np
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = [7.50, 3.50]
    plt.rcParams["figure.autolayout"] = True
    
    x = np.array([5, 4, 1, 4, 5])
    y = np.sort(x)
    
    plt.title("Line graph")
    plt.plot(x, y, color="red")
    
    plt.show()
  • Làm thế nào để vẽ các vectơ trong python bằng matplotlib?
  • Làm thế nào để vẽ MFCC trong Python bằng cách sử dụng matplotlib?
  • Làm thế nào để vẽ đồ thị 3D bằng python matplotlib?
  • Làm thế nào để một cốt truyện cốt truyện trong matplotlib python?
  • Làm thế nào để vẽ sơ đồ phổ cường độ theo chiều dọc trong matplotlib bằng cách sử dụng python?
  • Làm thế nào để vẽ sơ đồ bộ sưu tập. Biểu đồ bằng cách sử dụng matplotlib?
  • Làm thế nào để vẽ dữ liệu CSV bằng cách sử dụng matplotlib và pandas trong Python?
  • Làm thế nào để vẽ một khu vực trong khung dữ liệu gấu trúc trong matplotlib python?
  • Làm thế nào để vẽ CDF trong matplotlib trong python?
  • Làm thế nào để vẽ tín hiệu trong matplotlib trong python?
  • Biểu đồ tần số trong khung dữ liệu Python/Pandas bằng cách sử dụng matplotlib
  • Làm thế nào để vẽ một ma trận hình ảnh hoạt hình trong matplotlib?
  • Matplotlib - âm mưu trên nền hình ảnh trong Python
  • Làm thế nào để vẽ một tệp wav bằng matplotlib?

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Cải thiện bài viết

    Lưu bài viết

    Đọcpyplot(), which is used to plot two-dimensional data.

    Các chức năng khác nhau được sử dụng được giải thích dưới đây:

    • np.arange (bắt đầu, kết thúc): hàm này trả về các giá trị cách đều nhau từ khoảng [bắt đầu, kết thúc).This function returns equally spaced values from the interval [start, end).
    • plt.title (): Nó được sử dụng để đưa ra một tiêu đề cho biểu đồ. Tiêu đề được truyền làm tham số cho hàm này.It is used to give a title to the graph. Title is passed as the parameter to this function.
    • plt.xlabel (): Nó đặt tên nhãn tại trục x. Tên của trục x được truyền làm đối số cho hàm này.It sets the label name at X-axis. Name of X-axis is passed as argument to this function.
    • plt.ylabel (): Nó đặt tên nhãn tại trục y. Tên của trục y được truyền như là đối số cho hàm này.It sets the label name at Y-axis. Name of Y-axis is passed as argument to this function.
    • plt.plot (): Nó biểu thị các giá trị của các tham số được truyền cho nó cùng nhau.It plots the values of parameters passed to it together.
    • plt.show (): Nó hiển thị tất cả các biểu đồ cho bảng điều khiển.It shows all the graph to the console.

    Ví dụ 1 :

    Python3

    import numpy as np

    import matplotlib.pyplot as plt

    ____10

    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    2
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    3
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    4
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    5
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    7
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    0__
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    1

        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    2
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    3
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    5
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    6
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    8
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    9
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

    import numpy as np
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = [7.50, 3.50]
    plt.rcParams["figure.autolayout"] = True
    
    x = np.array([5, 4, 1, 4, 5])
    y = np.sort(x)
    
    plt.title("Line graph")
    plt.plot(x, y, color="red")
    
    plt.show()
    1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    1
    import numpy as np
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = [7.50, 3.50]
    plt.rcParams["figure.autolayout"] = True
    
    x = np.array([5, 4, 1, 4, 5])
    y = np.sort(x)
    
    plt.title("Line graph")
    plt.plot(x, y, color="red")
    
    plt.show()
    3
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

    import numpy as np
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = [7.50, 3.50]
    plt.rcParams["figure.autolayout"] = True
    
    x = np.array([5, 4, 1, 4, 5])
    y = np.sort(x)
    
    plt.title("Line graph")
    plt.plot(x, y, color="red")
    
    plt.show()
    5

    & nbsp; đầu ra: & nbsp;
    Output : 

    Ví dụ 2:

    Python3

    import numpy as np

    import matplotlib.pyplot as plt

    ____10

    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    2
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    3
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    4
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    5
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    7
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    0__
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    1

        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    2
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    3
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    5
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    6
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    8
        len(raws) = 2
        type(raws) = 'list'
        np.shape(raws[0][0]) = (306, 10001)
        raws = 
    [(array([[ -4.13211217e-12,  -4.13287303e-12,  -4.01705259e-12, ...,
              1.36386023e-12,   1.65182851e-12,   2.00368966e-12],
           [  1.08914129e-12,   1.47828466e-12,   1.82257607e-12, ...,
             -2.70151520e-12,  -2.48631967e-12,  -2.28625548e-12],
           [ -7.80962369e-14,  -1.27119591e-13,  -1.73610315e-13, ...,
             -1.13219629e-13,  -1.15031720e-13,  -1.12106621e-13],
           ..., 
           [  2.52774254e-12,   2.32293195e-12,   2.02644002e-12, ...,
              4.20064191e-12,   3.94858906e-12,   3.69495394e-12],
           [ -4.38122146e-12,  -4.96229676e-12,  -5.47782145e-12, ...,
              3.93820033e-12,   4.18850823e-12,   4.34950629e-12],
           [ -1.07284424e-13,  -9.23447993e-14,  -7.89852400e-14, ...,
              7.92079631e-14,   5.60172215e-14,   3.04448868e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ])), (array([[ -6.71363108e-12,  -5.80501003e-12,  -4.95944514e-12, ...,
             -3.25087343e-12,  -2.68982494e-12,  -2.13637448e-12],
           [ -5.04818633e-12,  -4.65757005e-12,  -4.16084140e-12, ...,
             -4.26120531e-13,   2.20744290e-13,   7.81245614e-13],
           [  1.97329506e-13,   1.64543867e-13,   1.32679812e-13, ...,
              2.11645494e-13,   1.94795729e-13,   1.75781773e-13],
           ..., 
           [  3.04245661e-12,   2.28376461e-12,   1.54118900e-12, ...,
             -1.14020908e-14,  -8.04647589e-13,  -1.52676489e-12],
           [ -1.83485962e-13,  -5.22949893e-13,  -8.60038852e-13, ...,
              7.70312553e-12,   7.20825156e-12,   6.58362857e-12],
           [ -7.26357906e-14,  -7.11700989e-14,  -6.88759767e-14, ...,
             -1.04171843e-13,  -1.03084861e-13,  -9.68462427e-14]]), array([ 60.   ,  60.001,  60.002, ...,  69.998,  69.999,  70.   ]))]
    
    9
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

    import numpy as np
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = [7.50, 3.50]
    plt.rcParams["figure.autolayout"] = True
    
    x = np.array([5, 4, 1, 4, 5])
    y = np.sort(x)
    
    plt.title("Line graph")
    plt.plot(x, y, color="red")
    
    plt.show()
    1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    1import1
    for r in range(len(raws)):
            axes[r].plot(raws[r])
    
    6

    import numpy as np
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = [7.50, 3.50]
    plt.rcParams["figure.autolayout"] = True
    
    x = np.array([5, 4, 1, 4, 5])
    y = np.sort(x)
    
    plt.title("Line graph")
    plt.plot(x, y, color="red")
    
    plt.show()
    5

    & nbsp; đầu ra: & nbsp;
    Output : 


    Bạn có thể có một mảng các mảng trong Python không?

    Khoa học dữ liệu thực tế sử dụng mảng hai chiều Python là một mảng trong một mảng. Nó là một mảng các mảng. Trong loại mảng này, vị trí của một phần tử dữ liệu được giới thiệu bởi hai chỉ số thay vì một.Two dimensional array is an array within an array. It is an array of arrays. In this type of array the position of an data element is referred by two indices instead of one.

    Làm thế nào để bạn in một mảng các mảng trong Python?

    Sử dụng phương thức print () tương tự như trường hợp các mảng được triển khai bằng danh sách, chúng ta có thể trực tiếp chuyển tên mảng numpy cho phương thức in () để in các mảng. Ở đây, ARR và ARR_2D lần lượt là một mảng 1D và một mảng 2D. Similar to the case of arrays implemented using lists, we can directly pass NumPy array name to the print() method to print the arrays. Here, arr and arr_2d are one 1D and one 2D NumPy arrays respectively.

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

    Khoa học dữ liệu thực tế sử dụng Python..
    Đặt kích thước hình và điều chỉnh phần đệm giữa và xung quanh các ô phụ ..
    Tạo hai mảng, x và y, sử dụng numpy ..
    Đặt tiêu đề của đường cong bằng phương thức Tiêu đề () ..
    Sơ đồ các điểm dữ liệu x và y, với màu đỏ ..
    Để hiển thị hình, sử dụng phương thức show () ..

    Làm thế nào để bạn truy cập một mảng bên trong một mảng trong Python?

    Một mảng trong Python được sử dụng để lưu trữ nhiều giá trị hoặc mục hoặc các phần tử cùng loại trong một biến duy nhất.Chúng ta có thể truy cập các phần tử của một mảng bằng toán tử chỉ mục [].Tất cả những gì bạn cần làm để truy cập một yếu tố cụ thể là gọi cho mảng bạn đã tạo.using the index operator [] . All you need do in order to access a particular element is to call the array you created.