1

I have a data file including three columns of data. I want to make a plot as

  1. The first column is the x-axes.
  2. The second column is the y-axes.
  3. The third column is a colorful circle or square depending on the magnitude of data.

I want to plot this figure in latex using pgfplot or tikz. How can I do that?

The data file contains:

45. 25. 0.61566929
49. 27. 1.4956423
53. 29. 1.0057851
54. 29. 2.0100065
55. 29. -3.797218
68. 35. 1.5912051
69. 35. 3.2076212
72. 37. 1.4886461
73. 37. 3.3389691
76. 39. 3.0976278
77. 39. 0.79048738
81. 41. -3.4879389
85. 43. 3.6111543
93. 47. 2.7246307
97. 49. -0.68090255
104.    51. -2.0629526
105.    51. -2.6273176
108.    53. -0.89579787
109.    53. 1.2111116
112.    55. 0.91267194
113.    55. 2.0789467
117.    57. -0.71531635
121.    59. -2.3426783
127.    61. -1.8874818
128.    61. 1.3249636
128.    62. -3.6386031
130.    63. 0.8552304
131.    63. -0.50966059
132.    63. -0.47354559
137.    65. -1.9534796
138.    65. -0.96086419
140.    67. -0.015875729
141.    67. -0.041466669
142.    67. -1.3871099
145.    69. 2.8931587
146.    69. -1.2849569
147.    69. -2.2127883
150.    71. -0.99118163
151.    71. -1.3673929
153.    71. -1.8922444
155.    73. 2.2556468
156.    73. -1.4209409
157.    73. -0.29486705
160.    75. 0.72117233
161.    75. 1.0190017
164.    77. 0.56115283
165.    77. 3.4677529
166.    77. -0.38758378
167.    77. -0.93988979
170.    79. 1.0521958
171.    79. 2.1933898
172.    79. 0.015352506
177.    81. -0.70462686
185.    83. 1.2917595
3

So you want to get something like ...

% used PGFPlots v1.16
    \begin{filecontents*}{data.txt}
        45. 25. 0.61566929
        49. 27. 1.4956423
        53. 29. 1.0057851
        54. 29. 2.0100065
        55. 29. -3.797218
        68. 35. 1.5912051
        69. 35. 3.2076212
        72. 37. 1.4886461
        73. 37. 3.3389691
        76. 39. 3.0976278
        77. 39. 0.79048738
        81. 41. -3.4879389
        85. 43. 3.6111543
        93. 47. 2.7246307
        97. 49. -0.68090255
        104.    51. -2.0629526
        105.    51. -2.6273176
        108.    53. -0.89579787
        109.    53. 1.2111116
        112.    55. 0.91267194
        113.    55. 2.0789467
        117.    57. -0.71531635
        121.    59. -2.3426783
        127.    61. -1.8874818
        128.    61. 1.3249636
        128.    62. -3.6386031
        130.    63. 0.8552304
        131.    63. -0.50966059
        132.    63. -0.47354559
        137.    65. -1.9534796
        138.    65. -0.96086419
        140.    67. -0.015875729
        141.    67. -0.041466669
        142.    67. -1.3871099
        145.    69. 2.8931587
        146.    69. -1.2849569
        147.    69. -2.2127883
        150.    71. -0.99118163
        151.    71. -1.3673929
        153.    71. -1.8922444
        155.    73. 2.2556468
        156.    73. -1.4209409
        157.    73. -0.29486705
        160.    75. 0.72117233
        161.    75. 1.0190017
        164.    77. 0.56115283
        165.    77. 3.4677529
        166.    77. -0.38758378
        167.    77. -0.93988979
        170.    79. 1.0521958
        171.    79. 2.1933898
        172.    79. 0.015352506
        177.    81. -0.70462686
        185.    83. 1.2917595
    \end{filecontents*}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        only marks,
        scatter,
        point meta=explicit,
    ]
        \addplot table [meta index=2] {data.txt};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

  • 1
    Dear Stefan Pinnow. The data is right. In fact, I want to plot a three-dimensional plot in a two-dimensional figure. The first column should b considered as x-axes. The second column should be considered as y-axes. The third column should be at (the first column, the second column) with a colorful circle or square depending on its magnitude. For example, I want to have a colorful circle at ( 45, 25) with a colorful circle depending on 0.61566929. – HS8637 Aug 28 '18 at 18:44
  • 1
    Please look at en.wikipedia.org/wiki/Valley_of_stability. There three plots that are similar to what I want. – HS8637 Aug 28 '18 at 18:47
  • 1
    Dear Stefan Pinnow. If I want to have grid lines for each step, in both axes, what shall I do? – HS8637 Aug 29 '18 at 6:02
  • 2
    If you mean a grid at the axis ticks then add grid=both (see e.g. tex.stackexchange.com/a/247548/95441). – Stefan Pinnow Aug 29 '18 at 6:09
  • 2
    Great. And only if you want to: Besides accepting the answer you can also upvote it (by clicking on the arrows next to the score). – Stefan Pinnow Aug 29 '18 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.