1.利用matplotlib包繪圖,保存svg,再轉成emf矢量圖貼在文章里
用Python作圖保存的圖矢量格式為svg、eps、pdf的,不能直接插入word。
而Word本身只能接受wmf,emf格式的矢量圖。
所以svg的要借助其他軟件轉換。如用visio,illustrator等。這里推薦一個在線轉換工具。https://cloudconvert.com/svg-to-emf
常用的圖片格式解釋:
fig:matlab 默認的圖片保存格式,在其他軟件上一般不可用,可視為矢量圖。
eps: 矢量圖,適用於 LaTex。
SVG 指可伸縮矢量圖形 (Scalable Vector Graphics)
emf:矢量圖,適合 Word。
jpg:位圖,很古老的圖片格式,同時也幾乎是最常用的圖片格式。
bmp:位圖,未壓縮。
pdf:直接輸出為 pdf,親測和在 Word 中插入矢量圖再輸出為 pdf 效果相同。
png:位圖,無損壓縮。
使用案例:
# coding=utf-8 import numpy as np import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['Arial'] # 如果要顯示中文字體,則在此處設為:SimHei plt.rcParams['axes.unicode_minus'] = False # 顯示負號 x = np.array([1, 2, 3, 4, 5, 6]) VGG_supervised = np.array([2.9749694, 3.9357018, 4.7440844, 6.482254, 8.720203, 13.687582]) VGG_unsupervised = np.array([2.1044724, 2.9757383, 3.7754183, 5.686206, 8.367847, 14.144531]) ourNetwork = np.array([2.0205495, 2.6509762, 3.1876223, 4.380781, 6.004548, 9.9298]) # label在圖示(legend)中顯示。若為數學公式,則最好在字符串前后添加"$"符號 # color:b:blue、g:green、r:red、c:cyan、m:magenta、y:yellow、k:black、w:white、、、 # 線型:- -- -. : , # marker:. , o v < * + 1 plt.figure(figsize=(10, 5)) plt.grid(linestyle="--") # 設置背景網格線為虛線 ax = plt.gca() ax.spines['top'].set_visible(False) # 去掉上邊框 ax.spines['right'].set_visible(False) # 去掉右邊框 plt.plot(x, VGG_supervised, marker='o', color="blue", label="VGG-style Supervised Network", linewidth=1.5) plt.plot(x, VGG_unsupervised, marker='o', color="green", label="VGG-style Unsupervised Network", linewidth=1.5) plt.plot(x, ourNetwork, marker='o', color="red", label="ShuffleNet-style Network", linewidth=1.5) group_labels = ['Top 0-5%', 'Top 5-10%', 'Top 10-20%', 'Top 20-50%', 'Top 50-70%', ' Top 70-100%'] # x軸刻度的標識 plt.xticks(x, group_labels, fontsize=12, fontweight='bold') # 默認字體大小為10 plt.yticks(fontsize=12, fontweight='bold') # plt.title("example", fontsize=12, fontweight='bold') # 默認字體大小為12 plt.xlabel("Performance Percentile", fontsize=13, fontweight='bold') plt.ylabel("4pt-Homography RMSE", fontsize=13, fontweight='bold') plt.xlim(0.9, 6.1) # 設置x軸的范圍 plt.ylim(1.5, 16) # plt.legend() #顯示各曲線的圖例 plt.legend(loc=0, numpoints=1) leg = plt.gca().get_legend() ltext = leg.get_texts() plt.setp(ltext, fontsize=12, fontweight='bold') # 設置圖例字體的大小和粗細 plt.savefig('./filename.svg', format='svg') # 建議保存為svg格式,再用在線轉換工具轉為矢量圖emf后插入word中 plt.show()
word中插入emf格式的矢量圖:
效果:
參考文獻:
01 Matplotlib畫各種論文圖
https://blog.csdn.net/bskfnvjtlyzmv867/article/details/80352891
02 python matplotlib 論文畫圖代碼總結
https://blog.csdn.net/qq_27465499/article/details/86765944
03 期刊論文寫作之【python matplotlib 畫圖設置】
https://blog.csdn.net/qq_22522663/article/details/87916573