Trước hết kiểm tra nhận dạng. Hy vọng rằng mã của bạn thực sự đọc
for i in range[0:244]:
plt.figure[]
y = numpy.array[Data_EMG[i,:]]
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples]
plt.xlabel['Time[ms]']
plt.ylabel['EMG voltage[microV]']
pylab.plot[x, y]
pylab.show[block=True]
Tại mỗi lần lặp, bạn hoàn toàn tạo ra một con số mới. Điều đó rất không hiệu quả. Ngoài ra, bạn chỉ vẽ hình dáng của bạn trên màn hình và không thực sự lưu nó. Tốt hơn là
from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
Nên nhanh hơn nhiều.
Nội dung How-to Tại sao tôi có rất nhiều ve, và/hoặc tại sao chúng không đúng thứ tự?
Xác định mức độ của các nghệ sĩ trong hình
Kiểm tra xem một con số trống chưa
Tìm tất cả các đối tượng trong một hình của một loại nhất định
Ngăn chặn ticklabels có một phần bù
Lưu số liệu trong suốt
Lưu nhiều sơ đồ vào một tệp PDF
Nỗ chỗ cho nhãn đánh dấu
Căn chỉnh các ylabel của tôi trên nhiều ô con
Kiểm soát thứ tự vẽ của các yếu tố cốt truyện
Làm cho tỷ lệ khung hình cho các lô bằng nhau
Vẽ nhiều tỷ lệ trục y
Tạo hình ảnh mà không có cửa sổ xuất hiện
Làm việc với chủ đề
Tại sao tôi có rất nhiều ve, và/hoặc tại sao chúng không đúng thứ tự?#
Một nguyên nhân phổ biến cho hành vi đánh dấu không mong muốn là truyền một danh sách các chuỗi thay vì các số hoặc đối tượng DateTime. Điều này có thể dễ dàng xảy ra mà không cần thông báo khi đọc trong một tệp văn bản được phân phối bằng dấu phẩy. Matplotlib coi danh sách các chuỗi là các biến phân loại [vẽ các biến phân loại] và theo mặc định đặt một dấu hiệu cho mỗi loại và vẽ chúng theo thứ tự chúng được cung cấp.Plotting categorical variables], and by default puts one tick per category, and plots them in the order in which they are supplied.
import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots[1, 2, constrained_layout=True, figsize=[6, 2]] ax[0].set_title['Ticks seem out of order / misplaced'] x = ['5', '20', '1', '9'] # strings y = [5, 20, 1, 9] ax[0].plot[x, y, 'd'] ax[0].tick_params[axis='x', labelcolor='red', labelsize=14] ax[1].set_title['Many ticks'] x = [str[xx] for xx in np.arange[100]] # strings y = np.arange[100] ax[1].plot[x, y] ax[1].tick_params[axis='x', labelcolor='red', labelsize=14]
[Mã nguồn, PNG]
Giải pháp là chuyển đổi danh sách các chuỗi thành các số hoặc đối tượng DateTime [thường là
from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
1 hoặc from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
2].Để biết thêm thông tin, xem sửa chữa quá nhiều ve.Fixing too many ticks.
Xác định mức độ của các nghệ sĩ trong hình#
Đôi khi chúng ta muốn biết mức độ của một nghệ sĩ. Các đối tượng matplotlib
from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
3 có phương pháp from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
4 thường sẽ trả về mức độ của nghệ sĩ trong pixel. Tuy nhiên, một số nghệ sĩ, đặc biệt là văn bản, phải được hiển thị ít nhất một lần trước khi mức độ của họ được biết đến. Matplotlib cung cấp from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
5, nên được gọi trước khi gọi from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
6.Kiểm tra xem một con số trống chưa#
Trống rỗng thực sự có thể có nghĩa là những điều khác nhau. Con số có chứa bất kỳ nghệ sĩ nào không? Liệu một con số có trống
from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
7 vẫn được tính là trống? Là con số trống rỗng nếu nó được hiển thị màu trắng tinh khiết [có thể có những nghệ sĩ có mặt, nhưng họ có thể ở bên ngoài khu vực vẽ hoặc trong suốt]?Với mục đích ở đây, chúng tôi định nghĩa trống rỗng là: "Hình không chứa bất kỳ nghệ sĩ nào ngoại trừ đó là bản vá nền." Ngoại lệ cho nền là cần thiết, bởi vì theo mặc định, mỗi hình đều chứa
from os import path
data = numpy.array[Data_EMG] # convert complete dataset into numpy-array
x = pylab.linspace[EMG_start, EMG_stop, Amount_samples] # doesn´t change in loop anyway
outpath = "path/of/your/folder/"
fig, ax = plt.subplots[] # generate figure with axes
image, = ax.plot[x,data[0]] # initialize plot
ax.xlabel['Time[ms]']
ax.ylabel['EMG voltage[microV]']
plt.draw[]
fig.savefig[path.join[outpath,"dataname_0.png"]
for i in range[1, len[data]]:
image.set_data[x,data[i]]
plt.draw[]
fig.savefig[path.join[outpath,"dataname_{0}.png".format[i]]
8 vì bản vá nền. Định nghĩa này có thể được kiểm tra thông qua:def is_empty[figure]: """ Return whether the figure contains no Artists [other than the default background patch]. """ contained_artists = figure.get_children[] return len[contained_artists]