亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

pycharm中使用plt.show()的兼容性錯誤

pycharm中使用plt.show()的兼容性錯誤

慕絲7291255 2021-04-04 10:17:52
我想根據pycharm中的以下代碼繪制pca組件圖。import numpy as npimport matplotlib.pyplot as pltfrom sklearn import linear_model, decomposition, datasetsfrom sklearn.pipeline import Pipelinefrom sklearn.model_selection import GridSearchCVlogistic = linear_model.LogisticRegression()pca = decomposition.PCA()pipe = Pipeline(steps = [('pca',pca), ('logistic', logistic)])digits = datasets.load_digits()x_digits = digits.datay_digits = digits.target# plot pca spectrumpca.fit(x_digits)plt.figure(1, figsize=(4,3))# clear the current figureplt.clf()# add axesplt.axes([.2,.2,.7,.7])plt.plot(pca.explained_variance_, linewidth = 2)plt.xlabel('n_components')plt.ylabel('explained_variance_')# predictionn_comp = [20, 40, 64]# logspace default is base 10, this is 10^-4 to 10^4cs = np.logspace(-4, 4, 3)# parameters of pipelines can be set using '__' separated parameter names:estimator = GridSearchCV(pipe,                         dict(pca__n_components = n_comp,                              logistic__C = cs))estimator.fit(x_digits, y_digits)plt.axvline(estimator.best_estimator_.named_steps['pca'].n_components,            linestyle = ':',label = 'n_compoenents chosen')plt.legend(prop = dict(size = 12))plt.axis('tight')plt.show()我在spyder中嘗試了相同的代碼,但效果卻令人吃驚。pycharm plot設置有什么問題?spyder和pycharm都使用python 3.5。
查看完整描述

2 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

快速解決方案:在Pycharm中禁用Python Scientific plot窗口(然后它將使用默認的matplotlib后端)

File > Settings > Tools >  Python > show plots in tool window


查看完整回答
反對 回復 2021-04-20
  • 2 回答
  • 0 關注
  • 583 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號