我有一个使用文件内容的气泡图工作示例,其中最后一列定义了气泡的大小。
我想知道是否有任何方法可以在不使用文件内容的情况下实现相同的绘图?当您将它们添加为坐标时,LaTeX 是否有办法读取第三个值?
先感谢您!
\documentclass{article}
\usepackage[a4paper, left =2cm, top = 2cm, right = 2cm, bottom = 2cm]{geometry}
\usepackage[table,xcdraw]{xcolor}
\usepackage[document]{ragged2e}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\pgfplotsset{width=10cm,compat=1.9}
\pgfplotsset{compat=newest}
\newcolumntype{Y}{>{\centering\arraybackslash}X} %
\tikzset{every picture/.append style={font=\normalsize}} % size graph font
\begin{filecontents*}{temp1.dat}
x Price Val
A 180 14.42
B 869 171.7
C 448 144.342
D 821 20.5
E 790 80.9
F 219 42.5
G 582 61.65
\end{filecontents*}
\begin{document}
\flushleft
\begin{tikzpicture}
\begin{axis}[
width=4.5in,
height=3.5in,
xtick=data,
symbolic x coords = {A,B,C,D,E,F,G},
scale only axis,
colorbar,
xticklabel style={rotate=45,anchor=east,align=center},
]
\addplot[%
scatter=true,
only marks,
mark=*,
point meta=explicit,
visualization depends on = {0.2*\thisrow{Val} \as \perpointmarksize},
scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize},
] table [x={x},y={Price},meta index=2] {temp1.dat};
\end{axis}
\end{tikzpicture}%
\end{document}
答案1
您只需将文件内容转储到\addplot
. 即\addplot table[..] {<content of file>};
\documentclass{article}
\usepackage[a4paper, left =2cm, top = 2cm, right = 2cm, bottom = 2cm]{geometry}
\usepackage[table,xcdraw]{xcolor}
\usepackage[document]{ragged2e}
\usepackage{pgfplotstable} % loads pgfplots, which loads tikz, which loads graphicx
\usepackage{filecontents}
\pgfplotsset{width=10cm,compat=1.9}
\pgfplotsset{compat=newest}
\newcolumntype{Y}{>{\centering\arraybackslash}X} %
\tikzset{every picture/.append style={font=\normalsize}} % size graph font
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=4.5in,
height=3.5in,
xtick=data,
symbolic x coords = {A,B,C,D,E,F,G},
scale only axis,
colorbar,
xticklabel style={rotate=45,anchor=east,align=center},
]
\addplot[%
scatter=true,
only marks,
mark=*,
point meta=explicit,
visualization depends on = {0.2*\thisrow{Val} \as \perpointmarksize},
scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize},
] table [x={x},y={Price},meta index=2] {
x Price Val
A 180 14.42
B 869 171.7
C 448 144.342
D 821 20.5
E 790 80.9
F 219 42.5
G 582 61.65
};
\end{axis}
\end{tikzpicture}%
\end{document}