Cách thông thường để đặt màu dòng trong matplotlib là chỉ định nó trong lệnh lô. Điều này có thể được thực hiện bằng một chuỗi sau dữ liệu, ví dụ:
line, = plt.plot[[1,2,3], [4,5,3], color="blue"]
line.set_color["black"]
0 cho một đường màu đỏ hoặc bằng cách nêu rõ đối số line, = plt.plot[[1,2,3], [4,5,3], color="blue"]
line.set_color["black"]
1.import matplotlib.pyplot as plt
plt.plot[[1,2,3], [2,3,1], "r-"] # red line
plt.plot[[1,2,3], [5,5,3], color="blue"] # blue line
plt.show[]
Xem thêm tài liệu của lệnh cốt truyện.
Trong trường hợp bạn đã có một dòng có một màu nhất định, bạn có thể thay đổi điều đó bằng phương pháp
line, = plt.plot[[1,2,3], [4,5,3], color="blue"]
line.set_color["black"]
2.line, = plt.plot[[1,2,3], [4,5,3], color="blue"]
line.set_color["black"]
Đặt màu của một dòng trong một âm mưu gấu trúc cũng được thực hiện tốt nhất tại điểm tạo ra cốt truyện:
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame[{ "x" : [1,2,3,5], "y" : [3,5,2,6]}]
df.plot["x", "y", color="r"] #plot red line
plt.show[]
Nếu bạn muốn thay đổi màu này sau này, bạn có thể làm như vậy bằng cách
plt.gca[].get_lines[][0].set_color["black"]
Điều này sẽ giúp bạn có được dòng đầu tiên [có thể là duy nhất] của các trục hoạt động hiện tại. Trong trường hợp bạn có nhiều trục hơn trong cốt truyện, bạn có thể vượt qua chúng
In case you have more axes in the plot, you could loop through them
for ax in plt.gcf[].axes:
ax.get_lines[][0].set_color["black"]
Và nếu bạn có nhiều dòng hơn, bạn cũng có thể lặp lại chúng.
một chức năng có thể gọi được
plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses
a.plot[x1, y1, 'g^', x2, y2, 'g-']5
[’Mông | ‘Vòng tròn | Projecting,]
a.plot[x1, y1, 'g^', x2, y2, 'g-']6
a.plot[x1, y1, 'g^', x2, y2, 'g-']
[‘MITER | ‘Vòng tròn | ‘Bevel,]
a.plot[x1, y1, 'g^', x2, y2, 'g-']7
Trình tự mực bật/tắt theo điểm
a.plot[x1, y1, 'g^', x2, y2, 'g-']9 | một ví dụ plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]0 |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]1 | [’Đầy đủ | Bên trái | Đúng vậy | ‘Đáy | Top | 'không ai'] |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]2 | một chuỗi ID |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]3 | sự vật |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]4 hoặc ls | [‘Solid | ‘Dashed,‘ Dashdot, ‘chấm chấm | [Offset, Off-Dash-Seq] | 6 | 7 | 8 | 9 | plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]9 | plot[x1, y1, x2, y2, antialiased=False]0 | plot[x1, y1, x2, y2, antialiased=False]1] |
plot[x1, y1, x2, y2, antialiased=False]2 hoặc LW | giá trị nổi trong các điểm |
plot[x1, y1, x2, y2, antialiased=False]3 | plot[x1, y1, x2, y2, antialiased=False]4 |
plot[x1, y1, x2, y2, antialiased=False]5 hoặc MEC | plot[x1, y1, x2, y2, antialiased=False]6 hoặc Mew |
plot[x1, y1, x2, y2, antialiased=False]7 hoặc MFC | plot[x1, y1, x2, y2, antialiased=False]8 hoặc MFCALT |
plot[x1, y1, x2, y2, antialiased=False]9 hoặc MS | trôi nổi |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].0 | [Không có | int | Độ dài-2 tuple của int | lát cắt | Danh sách/mảng của int | FLOAT | Chiều dài-2 tuple của float] |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].1 | plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].2 |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].3 | Khoảng cách nổi trong các điểm hoặc chức năng chọn có thể gọi plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].4 |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].5 | khoảng cách nổi trong điểm |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].6 | bool hoặc không có |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].7 | . |
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].8 | plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].9 |
00 | 01 |
một ví dụ 02 | 03 |
một chuỗi URL | 04 |
05 | Mảng 1d |
06 | 07 |
Kwargs scalex và scaley, nếu được xác định, được chuyển sang 08 để xác định xem các trục X và Y có được tự động phát hiện hay không; Mặc định là đúng. | Ghi chú |
Ngoài các đối số được mô tả ở trên, hàm này có thể lấy đối số từ khóa dữ liệu. Nếu đối số dữ liệu như vậy được đưa ra, các đối số sau được thay thế bằng dữ liệu []: | Tất cả các đối số với các tên sau: ‘X,‘ Y. |
Lô đất và/hoặc đánh dấu cho 3. Args là một đối số độ dài thay đổi, cho phép nhiều cặp x, y với chuỗi định dạng tùy chọn. Ví dụ, mỗi điều sau đây là hợp pháp: | Nếu x và/hoặc y là 2 chiều, thì các cột tương ứng sẽ được vẽ. |
Nếu được sử dụng với dữ liệu được dán nhãn, hãy đảm bảo rằng thông số màu không được bao gồm làm phần tử trong dữ liệu, vì nếu không thì trường hợp cuối cùng 4 có thể được hiểu là trường hợp đầu tiên sẽ làm 5 bằng cách sử dụng kiểu và màu mặc định. | Nếu không được sử dụng với dữ liệu được dán nhãn [tức là, không có đối số dữ liệu], một số lượng tùy ý của các nhóm X, Y, FMT có thể được chỉ định, như trong: |
Giá trị trả về là một danh sách các dòng đã được thêm vào.
a.plot[x1, y1, 'g^', x2, y2, 'g-']9 | một ví dụ plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]0 |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]1 | [’Đầy đủ | Bên trái | Đúng vậy | ‘Đáy | Top | 'không ai'] |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]2 | một chuỗi ID |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]3 | sự vật |
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]4 hoặc ls | [‘Solid | ‘Dashed,‘ Dashdot, ‘chấm chấm | [Offset, Off-Dash-Seq] | 6 | 7 | 8 | 9 | plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]9 | plot[x1, y1, x2, y2, antialiased=False]0 | plot[x1, y1, x2, y2, antialiased=False]1] |
plot[x1, y1, x2, y2, antialiased=False]2 hoặc LW | giá trị nổi trong các điểm |
plot[x1, y1, x2, y2, antialiased=False]3 | plot[x1, y1, x2, y2, antialiased=False]4 |
plot[x1, y1, x2, y2, antialiased=False]5 hoặc MEC | plot[x1, y1, x2, y2, antialiased=False]6 hoặc Mew |
plot[x1, y1, x2, y2, antialiased=False]7 hoặc MFC
plot[x1, y1, x2, y2, antialiased=False]8 hoặc MFCALT
plot[x1, y1, x2, y2, antialiased=False]9 hoặc MS
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]
Nếu bạn tạo nhiều dòng với một lệnh lô, kwargs áp dụng cho tất cả các dòng đó, ví dụ:
plot[x1, y1, x2, y2, antialiased=False]
Cả dòng sẽ không bị antialiased.
Bạn không cần sử dụng chuỗi định dạng, chỉ là chữ viết tắt. Tất cả các thuộc tính dòng có thể được kiểm soát bởi các đối số từ khóa. Ví dụ: bạn có thể đặt màu, điểm đánh dấu, lineStyle và MarkerColor với:
plot[x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12].
Xem
plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses0 để biết chi tiết.
Các kwarg là các thuộc tính
plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses0:
Tài sảnSự mô tả plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses2một hàm bộ lọc, lấy mảng float [m, n, 3] và giá trị DPI và trả về mảng A [M, N, 3] plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses3Phao [0,0 trong suốt đến 1,0 mờ] plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses4bool plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses5 hoặc AA[Đúng | Sai] plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses6một ví dụ plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses7 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses8bool plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses5 hoặc AA[Đúng | Sai] plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses6một ví dụ plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses7 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses8 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses9[[ a.plot[x1, y1, 'g^', x2, y2, 'g-']0,a.plot[x1, y1, 'g^', x2, y2, 'g-']1] |a.plot[x1, y1, 'g^', x2, y2, 'g-']2 | Không có] a.plot[x1, y1, 'g^', x2, y2, 'g-']3 hoặc cBất kỳ màu matplotlib a.plot[x1, y1, 'g^', x2, y2, 'g-']4một chức năng có thể gọi được a.plot[x1, y1, 'g^', x2, y2, 'g-']5[’Mông | ‘Vòng tròn | Projecting,] a.plot[x1, y1, 'g^', x2, y2, 'g-']6[‘MITER | ‘Vòng tròn | ‘Bevel,] a.plot[x1, y1, 'g^', x2, y2, 'g-']7Trình tự mực bật/tắt theo điểm a.plot[x1, y1, 'g^', x2, y2, 'g-']8[‘Mặc định | Bước Bước | ‘Bước-pre | ’Bước-mid | ‘BƯỚC-POST]] a.plot[x1, y1, 'g^', x2, y2, 'g-']9một ví dụ plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]0 plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]1[’Đầy đủ | Bên trái | Đúng vậy | ‘Đáy | Top | 'không ai'] plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]2một chuỗi ID plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]3sự vật plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]4 hoặc ls[‘Solid | ‘Dashed,‘ Dashdot, ‘chấm chấm | [Offset, Off-Dash-Seq] | 6 |line, = plt.plot[[1,2,3], [4,5,3], color="blue"] line.set_color["black"]
7 |line, = plt.plot[[1,2,3], [4,5,3], color="blue"] line.set_color["black"]
8 |line, = plt.plot[[1,2,3], [4,5,3], color="blue"] line.set_color["black"]
9 |line, = plt.plot[[1,2,3], [4,5,3], color="blue"] line.set_color["black"]
plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]9 |plot[x1, y1, x2, y2, antialiased=False]0 |plot[x1, y1, x2, y2, antialiased=False]1]một ví dụ plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses7 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses8 plot[[1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2] plot[[1,2,3], [1,4,9], 'rs', label='line 2'] axis[[0, 4, 0, 10]] legend[]3sự vật một ví dụ plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses7 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses8một ví dụ plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses7 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses8 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses9[[ a.plot[x1, y1, 'g^', x2, y2, 'g-']0,a.plot[x1, y1, 'g^', x2, y2, 'g-']1] |a.plot[x1, y1, 'g^', x2, y2, 'g-']2 | Không có] a.plot[x1, y1, 'g^', x2, y2, 'g-']3 hoặc cBất kỳ màu matplotlib a.plot[x1, y1, 'g^', x2, y2, 'g-']4một chức năng có thể gọi được a.plot[x1, y1, 'g^', x2, y2, 'g-']5[’Mông | ‘Vòng tròn | Projecting,] a.plot[x1, y1, 'g^', x2, y2, 'g-']6[‘MITER | ‘Vòng tròn | ‘Bevel,] a.plot[x1, y1, 'g^', x2, y2, 'g-']7Trình tự mực bật/tắt theo điểm a.plot[x1, y1, 'g^', x2, y2, 'g-']8[‘Mặc định | Bước Bước | ‘Bước-pre | ’Bước-mid | ‘BƯỚC-POST]] a.plot[x1, y1, 'g^', x2, y2, 'g-']7Trình tự mực bật/tắt theo điểm a.plot[x1, y1, 'g^', x2, y2, 'g-']3 hoặc cBất kỳ màu matplotlib a.plot[x1, y1, 'g^', x2, y2, 'g-']4một chức năng có thể gọi được a.plot[x1, y1, 'g^', x2, y2, 'g-']5[’Mông | ‘Vòng tròn | Projecting,] a.plot[x1, y1, 'g^', x2, y2, 'g-']6[‘MITER | ‘Vòng tròn | ‘Bevel,] bool plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses5 hoặc AA[Đúng | Sai] plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses6[Đúng | Sai] plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses6 plot[x, y] # plot x and y using default line style and color plot[x, y, 'bo'] # plot x and y using blue circle markers plot[y] # plot y using x as index array 0..N-1 plot[y, 'r+'] # ditto, but with red plusses9
[[
a.plot[x1, y1, 'g^', x2, y2, 'g-']0,
a.plot[x1, y1, 'g^', x2, y2, 'g-']1] |
a.plot[x1, y1, 'g^', x2, y2, 'g-']2 | Không có]
a.plot[x1, y1, 'g^', x2, y2, 'g-']3 hoặc c
Bất kỳ màu matplotlibdata keyword argument. If such a data argument is given, the following arguments are replaced by data[]:
a.plot[x1, y1, 'g^', x2, y2, 'g-']
4