文章目录
前言
这几天在帮忙干活儿,记录一下,方便自己写文章的时候备忘。
tag: LaTex; plot
1. excel表转Latex表
1.1 tables generator
Tables Generator,一个可以把excel表转成latex格式表的在线小工具。
File → Paste Table Data 即可。
需要双横线的地方需要自己改一下\hline \hline
2. 插入latex
新建一个table.tex
,并在里面输入:
\begin{table}[t]
\caption{table caption}}
\label{tab:table1}
% \vspace{-6pt}
\centering
\resizebox{\columnwidth}{!}{
% 这里放入从tables generator里获得的内容
% 从\begin{tabular}开始
% 到\end{tabular}结束
}
\end{table}
然后在原文中通过\input{tables/table}
的方式插入即可。
2. 【笨方法】从tensorBoard获取csv文件,绘图并插入latex文件
参考:
2.1 从tensorBoard获取csv文件
标签选SCALARS,勾选Show data download links,点图像右下角的run to download,然后选csv。
得到的csv文件表头是这样的:| Wall time | Step | Value |
2.2 使用python画图
plt.figure(figsize = (6, 4))
:图片大小600px*400px;小图这么大就行,大图可以用11*8。plt.plot(x2, y2, color=(36/255,85/255,164/255), label='label-1', linewidth =2.5)
:RGB自定义颜色,线宽=2.5plt.xticks(fontsize=18)
:x坐标,坐标轴的字符大小18plt.legend(fontsize=14)
:显示标注
# script.py
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import pandas as pd
from matplotlib.font_manager import FontProperties
import csv
file_tail = "Accuracy"
def readcsv(files, weight=0.6):
data = pd.read_csv(filepath_or_buffer=files,header=0,names=['Step','Value'],dtype={'Step':np.int,'Value':np.float})
scalar = data['Value'].values
last = scalar[0]
smoothed = []
for point in scalar:
# === smooth操作 ===
# smoothed_val = last * weight + (1 - weight) * point
# smoothed.append(smoothed_val)
# last = smoothed_val
smoothed.append(point)
return data['Step'].values, smoothed
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'
plt.figure(figsize = (6, 4))
x,y=readcsv(f'chartname_{file_tail}.csv')
plt.plot(x2, y2, color=(36/255,85/255,164/255), label='label-1', linewidth =2.5)
x1,y1=readcsv(f'chartname_{file_tail}.csv')
plt.plot(x1, y1, color=(255/255,165/255,16/255), label='label-2', linewidth =2.5)
x2,y2=readcsv(f'chartname_{file_tail}.csv')
plt.plot(x2, y2, color=(12/255,132/255,198/255), label='label-3', linewidth =2.5)
x3,y3=readcsv(f'chartname_{file_tail}.csv')
plt.plot(x3, y3, color=(247/255,77/255,77/255), label='label-4', linewidth =2.5)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
plt.xlim(0, 200)
plt.ylim(0.2, 0.8)
plt.xlabel('Epoch',fontsize=22)
plt.ylabel("Acc",fontsize=22)
plt.legend(fontsize=14)
plt.show()
2.3 latex图片排版
新建一个fig.tex
并在内部进行多图排版,我希望排一行两个图,排三行。
排版好后在原文内通过\input{figure/fig}
的方式插入即可。
\begin{figure}[htbp]
\centering
\begin{minipage}{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{figures/alpha_beta/a-1.png}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{figures/alpha_beta/b-1.png}
\end{minipage}
%\qquad
\begin{minipage}{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{figures/alpha_beta/a-2.png}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{figures/alpha_beta/b-2.png}
\end{minipage}
%\qquad
\begin{minipage}{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{figures/alpha_beta/a-3.png}
\end{minipage}
\begin{minipage}{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{figures/alpha_beta/b-3.png}
\end{minipage}
\caption{fig Caption}
\label{fig:fig1}
\end{figure}
3. 【自用】论文画图配色参考
出处很杂乱。
5色配色组
颜色 | RGB | 16进 |
---|---|---|
█████████ | (40, 120, 181) | #2878B5 |
█████████ | (154, 201, 219) | #9AC9DB |
█████████ | (248, 172, 140) | #F8AC8C |
█████████ | (200, 36, 36) | #C82423 |
█████████ | (255, 136, 132) | #FF884 |
6色配色组(色盲友好)
颜色 | RGB | 16进 |
---|---|---|
█████████ | (230, 159,0) | #E69F00 |
█████████ | (86, 180, 233) | #56B4E9 |
█████████ | (0, 158, 115) | #009E73 |
█████████ | (240,228,66) | #F0E442 |
█████████ | (204, 228, 66) | #CC79A7 |
█████████ | (213, 94, 0) | #D55E00 |
█████████ | (0,114,178) | #0072B2 |
4色配色组
颜色 | RGB | 16进 |
---|---|---|
█████████ | (232,17,15) | #e8110f |
█████████ | (251,199,35) | #fbc723 |
█████████ | (27,106,165) | #1b6aa5 |
█████████ | (51,51,51) | #333333 |
5色配色组
颜色 | RGB | 16进 |
---|---|---|
█████████ | (100,146,190) | #6492be |
█████████ | (168,199,123) | #a8c77b |
█████████ | (222,167,105) | #e4a352 |
█████████ | (217,110,116) | #d96e74 |
█████████ | (206,147,181) | #ce93b5 |