簡體   English   中英

軸不與 add_axes 一起顯示

[英]axes are not displayed with add_axes

代碼正在執行,甚至顯示圖表,但無法查看 x 軸和 y 軸。 圖例顯示但沒有顯示軸,我嘗試調整 dpi 但沒有幫助。 我正在使用 vscode

import matplotlib.pyplot as plt 
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
ax.bar(langs, students)
plt.ylim(0,35)
plt.show() 

output:

在此處輸入圖像描述

add_axes([0,0,1,1])使坐標軸 position 從 canvas 的左下點開始,從而導致坐標軸在圖中的 canvas 之外。 您可以刪除add_axes並嘗試plt.bar(langs,students)代替。 完整代碼:

import matplotlib.pyplot as plt 
fig = plt.figure()
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
plt.bar(langs, students)
plt.ylim(0,35)
plt.show() 

和圖

在此處輸入圖像描述

或者如果你想用ax這么糟糕,你可以使用fig, ax = plt.figure()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM