Các ô đường viền có thể được tạo bằng Matplotlib. Trong Kỹ thuật Xây dựng, một biểu đồ đường viền có thể hiển thị cấu trúc liên kết của một tòa nhà. Trong Kỹ thuật cơ khí, một biểu đồ đường viền có thể hiển thị độ dốc ứng suất trên bề mặt một phần
Phương pháp import numpy as np
import matplotlib.pyplot as plt
# if using a Jupyter notebook, include:
%matplotlib inline
x = np.arange[-3.0, 3.0, 0.1]
y = np.arange[-3.0, 3.0, 0.1]
X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
9 của Matplotlib
x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Xây dựng các biểu đồ đường viền với Matplotlib đòi hỏi phải sử dụng phương pháp
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline0. Cuộc gọi phương thứcx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline0 cơ bản bên dướix = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
ax.contour[X, Y, Z]
Trong đó
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline1 vàx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline2 là mảng 2D của các điểm x và y và Z là mảng 2D gồm các điểm xác định "chiều cao" của đường bao, được biểu thị bằng màu trong biểu đồ 2Dx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Đoạn mã bên dưới bao gồm hàm
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline3 của NumPy tạo hai mảng 2D từ hai mảng 1Dx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Trong 1]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inlinex = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Phương pháp import numpy as np
import matplotlib.pyplot as plt
# if using a Jupyter notebook, include:
%matplotlib inline
x = np.arange[-3.0, 3.0, 0.1]
y = np.arange[-3.0, 3.0, 0.1]
X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
9 của Matplotlib
x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Phương pháp Matplotlib _______ 15 tương tự như ________ 30 ngoại trừ việc ________ 15 tạo ra các biểu đồ đường viền được "điền". Thay vì các dòng trong một ô
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline0, các khu vực bóng mờ được tạo ra bởi một ôx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline5. Cuộc gọi phương thức chung chox = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline5 tương tự nhưx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline0x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
ax.contourf[X, Y, Z]
Trong đó
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline1 vàx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline2 là mảng 2D của các điểm x và y và Z là mảng 2D gồm các điểm xác định màu của các vùng trên biểu đồ 2Dx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Phần mã tiếp theo xây dựng biểu đồ đường viền bóng mờ bằng cách sử dụng phương pháp
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline5 của Matplotlibx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Trong 2]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline3x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Thanh màu trên ô đường viền
Vì màu sắc đại diện cho chiều thứ ba [như "cao"] trên biểu đồ 2D nên sẽ hữu ích khi có tỷ lệ cho ý nghĩa của từng màu. Một thang màu thường được biểu diễn bên cạnh một ô
Các thanh màu được thêm vào các ô đường viền Matplotlib bằng phương pháp
ax.contourf[X, Y, Z]
5. Vì thanh màu không phải là một phần của biểu đồ đường bao nên thanh màu cần được áp dụng cho đối tượng hình, thường được gọi là ax.contourf[X, Y, Z]
6. Một biểu đồ đường viền cần được chuyển vào phương thức ax.contourf[X, Y, Z]
5. Do đó, khi bạn thêm một thanh màu vào một hình, một đối tượng vẽ cần phải có sẵn. Một đối tượng cốt truyện là đầu ra của phương thức import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline5x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Trước đây, đầu ra của phương thức
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline5 không được gán cho một biến. Nhưng để bao gồm một thanh màu trên biểu đồ đường viền, đối tượng biểu đồ cần được lưu vào một biến, để đối tượng biểu đồ có thể được truyền cho phương thứcx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
ax.contourf[X, Y, Z]
5import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline0x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Trong đó
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline31 là đối tượng cốt truyện được tạo bởix = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline32. Đối tượng axis chứa biểu đồ đường bao,x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline33 được truyền cho phương thứcx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
ax.contourf[X, Y, Z]
5 cùng với đối tượng biểu đồ import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline31x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Đoạn mã bên dưới tạo một biểu đồ đường viền được tô với một thanh màu được đặt bên cạnh biểu đồ
Trong 3]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline6x = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
Bản đồ màu trên các ô đường viền
Bảng màu mặc định của đường viền Matplotlib và các ô đường viền đã điền có thể được sửa đổi. Một cách chung để sửa đổi lược đồ màu là gọi hàm
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline36 của Matplotlib để xuất ra một đối tượng bản đồ màu. Có nhiều bản đồ màu khác nhau có sẵn để áp dụng cho các ô đường viền. Một danh sách đầy đủ có sẵn trong tài liệu Matplotlib [https. // matplotlib. tổ chức]. Đối tượng colormap sau đó được chuyển đến phương thứcx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline5 hoặcx = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]
import numpy as np import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline0 dưới dạng đối số từ khóax = np.arange[-3.0, 3.0, 0.1] y = np.arange[-3.0, 3.0, 0.1] X, Y = np.meshgrid[x, y]
Z = np.sin[X]*np.cos[Y]
fig, ax = plt.subplots[figsize=[6,6]]
ax.contour[X,Y,Z]
plt.show[]