[英]How to get rid of black background in Matplotlib graph
我有這樣的圖表。
我為此編寫的代碼如下:
header=list(outcome)
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.patches as mpatches
fig = plt.figure(figsize=(25,20))
ax = fig.add_subplot(111, projection='3d')
red_patch = mpatches.Patch(color='red', label='Terminated')
green_patch = mpatches.Patch(color='green', label='Completed Positive')
blue_patch=mpatches.Patch(color='blue', label='Completed Negative')
plt.legend(handles=[red_patch,green_patch,blue_patch],fontsize=23)
plt.title('MDS by Phase '+phase,fontsize=23)
for x, y, w, name in zip(pos[:, 0], pos[:,1], pos[:, 2], header):
if(name=='Completed Negative'):
color='blue'
elif(name=='Completed Positive'):
color='green'
else:
color='red'
ax.scatter(x, y, w,s=65,c=color)
#fig.savefig('mds_ic_'+phase+'.png')
fig.savefig('mds_obj_auto_'+phase+'.png')
我不想要黑色背景,因為在將圖表粘貼到幻燈片上時它占用了太多空間但看起來很小,因為剩余空間是白色的,這不是圖表的一部分。 黑色部分不與白色背景凝膠
您可以嘗試添加以下行:
fig.patch.set_facecolor('white')
ax.set_axis_bgcolor('white')
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
一個用於刪除圖形周圍的背景,一個用於更改軸的顏色,最后三個用於更改每個軸的窗格顏色。
如果你想要黑色背景,最簡單的設置是matplotlib.pyplot.style.use('dark_background')
。
您可以從matplotlib.pyplot.style.available
中選擇一種樣式,然后通過use
設置您的選擇,例如matplotlib.pyplot.style.use('ggplot')
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.