需要安裝matplotlib庫,可以用如下命令安裝:
pip
install
matplotlib
txt文本數(shù)據(jù)如下所示(示例中的每一行內部用空格分開):
100 0.6692215
200 0.57682794
300 0.45037615
400 0.42214713
500 0.45073098
600 0.4728373
700 0.48083866
800 0.3751492
900 0.4249844
1000 0.36427215
1100 0.36209464
1200 0.40490758
1300 0.3774191
1400 0.34719718
1500 0.3648946
1600 0.261855
1700 0.4321903
1800 0.35071397
1900 0.279996
2000 0.30030474
適用于Python3的代碼如下所示:
import
matplotlib
.
pyplot
as
plt
input_txt
=
'demo.txt'
x
=
[
]
y
=
[
]
f
=
open
(
input_txt
)
for
line
in
f
:
line
=
line
.
strip
(
'\n'
)
line
=
line
.
split
(
' '
)
x
.
append
(
float
(
line
[
0
]
)
)
y
.
append
(
float
(
line
[
1
]
)
)
f
.
close
plt
.
plot
(
x
,
y
,
marker
=
'o'
,
label
=
'lost plot'
)
plt
.
xticks
(
x
[
0
:
len
(
x
)
:
2
]
,
x
[
0
:
len
(
x
)
:
2
]
,
rotation
=
45
)
plt
.
margins
(
0
)
plt
.
xlabel
(
"train step"
)
plt
.
ylabel
(
"lost"
)
plt
.
title
(
"matplotlip plot"
)
plt
.
tick_params
(
axis
=
"both"
)
plt
.
show
(
)
更多內容:
matplotlib官方繪圖示例參考:https://matplotlib.org/gallery/index.html
matplotlib PDF手冊:https://matplotlib.org/Matplotlib.pdf
matplotlib API文檔:https://matplotlib.org/api/index.html
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
