簡體   English   中英

如何從圖表中刪除框架-pyplot -matplotlib

[英]How to remove frame from a chart -pyplot -matplotlib

我知道這聽起來很簡單,但谷歌仍然無法幫助我完成它需要完成的方式

import matplotlib.pyplot as plt
import numpy as np

plt.figure()

languages =['Python', 'SQL', 'Java', 'C++', 'JavaScript']
pos = np.arange(len(languages))
popularity = [56, 39, 34, 34, 29]

plt.bar(pos, popularity, align='center')
plt.xticks(pos, languages)
plt.ylabel('% Popularity')
plt.title('Top 5 Languages for Math & Data \nby % popularity on Stack Overflow', alpha=0.8)

# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top='off', bottom='off', left='off', right='off', labelleft='off', labelbottom='on')

plt.show()

添加到您的腳本中,這將從圖表中刪除軸:

plt.axis('off')

您可以通過使用.axis()方法來實現這一點。

這是您需要添加的代碼語句:

plt.axis('off')

你會得到這個 output:

在此處輸入圖像描述

有兩種方法可以從 matplotlib.pyplot 圖表中刪除丑陋的框架:

import matplotlib.pyplot as plt
plt.box(False)

或者

import matplotlib.pyplot as plt
for spine in plt.gca().spines.values():
spine.set_visible(False)

暫無
暫無

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

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