0

I would like to create a surface plot (like the one shown below) from a .csv table containing three columns of data (x,y,phi) but all I get is a line plot (see second picture). The data table is downloadable from the provided link. If anyone knows how to get around this issue your help would be much appreciated.what i would like to get

what i get in latex

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}
\begin{document}

\section{Contour Plot}

\begin{tikzpicture} \begin{axis}[
title={computational potential}, xmin=-3, xmax=3, ymin=0, ymax=3,
view={0}{90},
colorbar horizontal,
mesh/ordering=x varies,
]
\addplot3 [surf,
] table [col sep=comma] {computational_potential.csv}; \end{axis}
\end{tikzpicture}

\end{document}

link to download .csv data

0

1 Answer 1

0

First I thought that because the data lies in lines, it does not span any surface, and can not be used. -but the different lines does span surface. Normally data would be formatted as

<x1> <y1> <z>
<x1> <y2> <z>
<x1> <y3> <z>

<x2> <y1> <z>
<x2> <y2> <z>
<x2> <y3> <z>

(from https://tex.stackexchange.com/a/50020/8650)

By inserting a single blank line in the data like this:

x   y   phi    
0.5,0,0.96965

0.58333,0,0.98098
0.66667,0,1.0104
0.75,0,1.0514
0.83333,0,1.1005
...

it triggers the surf to accept more than just the one line in space and generated this:

Graph

3
  • I would look into processing the data to conform with the correct format and not misuse a 3D surf plot for a 2D graph. Commented Jul 12, 2021 at 13:06
  • Thank you so much for your answer! (The main reason i tried using a 3d surf plot was only because it resulted in a slightly better output (relatively speaking) than a filled contour plot.)
    – albert1234
    Commented Jul 12, 2021 at 16:14
  • Please upvote and accept answer Commented Sep 12, 2021 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .