Và cuối cùng, trong trường hợp bạn có một thanh màu ngang và muốn chuyển các ve và nhãn lên trên cùng, bạn có thể sử dụng chức năng tương đương trên
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar6.
c_ax.xaxis.set_label_position['top']
c_ax.xaxis.set_ticks_position['top']
Đã trả ngày 29 tháng 4 năm 2016 lúc 13. 24 29 tháng 4, 2016 lúc 13. 24
tmdavisontmdavison tmdavison
60. 7K12 Huy hiệu vàng171 Huy hiệu bạc154 Huy hiệu đồng12 huy hiệu vàng171 huy hiệu bạc154 huy hiệu đồng
0
Vì một số lý do áp dụng các thay đổi cho các đầu nối vào thanh màu [tham số
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar7] không hoạt động với tôi
Tuy nhiên, hãy lấy các trục từ thanh màu của đối tượng và sau đó áp dụng các thay đổi hoạt động độc lập
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar1
Đã trả ngày 26 tháng 11 năm 2020 lúc 0. 08 26/11/2020 lúc 0. 08
Xrioxrio Xrio
1252 Huy hiệu bạc9 Huy hiệu Đồng2 huy hiệu bạc9 huy hiệu đồng
Tôi đã có cùng một vấn đề. Vấn đề này có thể phát sinh khi bạn đang thiết lập rõ ràng các phần của thanh màu. Trong trường hợp đó, bạn có thể dễ dàng chỉ định ở phía nào của các phần này, bạn nhận được các con lừa và nhãn. Ví dụ. nếu bạn đã tạo một hình ảnh bằng cách sử dụng imshow
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar2
Bạn có thể xác định trục cho thanh màu, trong ví dụ này bằng cách sử dụng inset_axes
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar0
Sau đó, thêm thanh màu của bạn
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar1
và sau đó kiểm tra vị trí giám sát của ve, v. v
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar2
Đã trả ngày 26 tháng 11 năm 2019 lúc 20. 25 26/11/2019 ở 20. 25
Tôi không biết tại sao, nhưng không có lệnh nào trong số này làm việc cho tôi. Nếu đó cũng là trường hợp của bạn, thì tôi đã giải quyết vấn đề bằng cách chỉ định thuộc tính ColorBar
fig, ax = plt.subplots[] data = np.clip[randn[250, 250], -1, 1] cax = ax.imshow[data, cmap=cm.coolwarm] ax.set_title['Gaussian noise with vertical colorbar'] # Add colorbar, make sure to specify tick locations to match desired ticklabels cbar = fig.colorbar[cax, ticks=[-1, 0, 1]] cbar.ax.set_yticklabels[['< -1', '0', '> 1']] # vertically oriented colorbar3
in that care all ve and label. Nếu bạn vẫn muốn thanh màu ở bên phải của cốt truyện, chỉ cần xác định một giới hạn mới của giới hạn ở vị trí bạn muốn và liên kết thanh màu của bạn với nó