y値または変数に応じてマークのサイズが異なります

y値または変数に応じてマークのサイズが異なります

散布図を作成し、mark size変数に応じて を変化させたいです。さらに、マークの色をファイルで指定されたメタ値 (指定されたコードで機能する) に応じて変化させたいです。例として、 のような非線形依存関係、または for ループの変数を使用したいです。マークのサイズには長さが想定されているようなので、またはいくつかのマクロmark size = sqrt(y value of point)を試しても成功しなかったため、計算を行う方法が見つかりません。\pgfmathresult\edef...

コードでマークのサイズを変更できました

scatter/@pre marker code/.style={/tikz/mark size={4-\pgfkeysvalueof{/data point/y}/4}},%\pgfmathparse{1}\pgfmathresult},
scatter/@post marker code/.style={}

ただし、メタ値へのカラーマッピングは失われます。

\documentclass[tikz, border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usepackage{amsmath}
\usepackage{filecontents}

\begin{filecontents*}{temp.dat}
1   1   100
2   2   200
3   3   300
4   4   400
5   5   500
6   6   600
7   7   700
8   8   800
9   9   900
10  10  1000
\end{filecontents*}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
    width=4.5in,
    height=3.5in,
    scale only axis,
    xmin=0,
    xmax=10,
    ymin=0,
    ymax=10,
    axis x line*=bottom,
    axis y line*=left,
    colorbar
]

\addplot[%
    scatter=true,
    only marks,
    mark=*,
    color=blue,
    point meta=explicit symbolic,
    %scatter/@pre marker code/.style={/tikz/mark size= f (yvalue)?},
    %scatter/@post marker code/.style={}
] table [meta index=2] {temp.dat};
\end{axis}
\end{tikzpicture}%
\end{document}

サンプルコードはここからコピーされます:マーカー サイズのメタデータを使用する場合、同じマークの色を維持するにはどうすればよいですか?

答え1

編集:

最初に提出した回答にいくつか問題が見つかりました。問題は欠落だと思いました\usepackage{filecontents}が、Jake が指摘したように、それは問題ではないはずです。とにかく、マークのサイズとカラーバーのスケールが実際に値を表す 2 番目のソリューションを追加しましたy

\documentclass[tikz, border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usepackage{amsmath}
\usepackage{filecontents}

\begin{filecontents*}{temp.dat}
x   y
1   1
2   4
3   9
4   16
5   25
6   36
7   49
8   64
9   81
10  100
\end{filecontents*}

\begin{document}
\pgfplotstableread{temp.dat}{\tempdat}
\begin{tikzpicture}

\begin{axis}[%
    width=4.5in,
    height=3.5in,
    scale only axis,
    xmin=0,
    xmax=10,
    ymin=0,
    axis x line*=bottom,
    axis y line*=left,
    colorbar
]
\addplot[%
    scatter=true,
    only marks,
    mark=*,
    color=blue,
    visualization depends on = {y/2 \as \perpointmarksize},
    scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize},
] table [x={x},y={y}] {\tempdat};
\end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

元の回答:

コメント行を次の行に置き換えると動作します (マニュアルのセクション 4.25 を参照)。

visualization depends on = {y \as \perpointmarksize},
scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize},

完全なコード:

\documentclass[tikz, border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usepackage{amsmath}

\begin{filecontents*}{temp.dat}
1   1   100
2   2   200
3   3   300
4   4   400
5   5   500
6   6   600
7   7   700
8   8   800
9   9   900
10  10  1000
\end{filecontents*}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
    width=4.5in,
    height=3.5in,
    scale only axis,
    xmin=0,
    xmax=10,
    ymin=0,
    ymax=10,
    axis x line*=bottom,
    axis y line*=left,
    colorbar
]

\addplot[%
    scatter=true,
    only marks,
    mark=*,
    color=blue,
    point meta=explicit symbolic,
    visualization depends on = {y \as \perpointmarksize},
    scatter/@pre marker code/.append style={/tikz/mark size=\perpointmarksize},
] table [meta index=2] {temp.dat};
\end{axis}
\end{tikzpicture}%
\end{document}

ここに画像の説明を入力してください

関連情報