Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to plot 3d data as 2d (please refer to the attached figureenter image description here).

Is that possible at all in Tex (or Matlab)?(Usually, this is done a s a legend, however, when no colors are allowed, I have to plot it as in the attached picture). If so, please provide any hints. Thank you in advance

Here is also a sample of the data:

X=[0 0 0 0 0
0.00499487214258387 0.0100271322719341  0.0151355841667174  0.0203619904285679  0.0257528910437245
0.00703013931750997 0.0141123715001326  0.0213007419561194  0.0286533748405864  0.0362349750090093
0.00856912164753604 0.0172011015018718  0.0259611298569260  0.0349192664533911  0.0441534216317338
0.00984769541100846 0.0197669024060679  0.0298317587516411  0.0401218833508729  0.0507257254049430
0.0109577332470996  0.0219942405774403  0.0331911596116199  0.0446361019206510  0.0564262963381876
0.0119466084732432  0.0239782392419037  0.0361829739474490  0.0486552739640120  0.0614998638245181
0.0128426154484001  0.0257757149277838  0.0388930053871466  0.0522949117805015  0.0660926587477192
0.0136642899493110  0.0274238903416811  0.0413774721254582  0.0556307081325855  0.0703005193527485
0.0144245776620953  0.0289487637697525  0.0436756433487295  0.0587155421791397  0.0741904098771546
0.0151329564382696  0.0303693701768318  0.0458162730087464  0.0615881383770832  0.0778113778863288
0.0157966212085941  0.0317001603416950  0.0478211921655991  0.0642779014739504  0.0812006730740997
0.0164211931300526  0.0329524247496926  0.0497074590478197  0.0668078104510510  0.0843874098612964
0.0170111676966756  0.0341351933703888  0.0514887177522871  0.0691962474012896  0.0873948821954542
0.0175702105696051  0.0352558296774944  0.0531760952694321  0.0714582050315404  0.0902420919849960
0.0181013600452389  0.0363204372087640  0.0547788154484420  0.0736061131758165  0.0929447953582426
0.0186071698801841  0.0373341463673818  0.0563046321253931  0.0756504218986758  0.0955162408504069
0.0190898126701751  0.0383013220178056  0.0577601426467341  0.0776000236025984  0.0979677038151599
0.0195511563564558  0.0392257171221451  0.0591510199088859  0.0794625654482437  0.100308881996065
0.0199928219502558  0.0401105886622858  0.0604821874442227  0.0812446851052654  0.102548194045946];

Y=[1 1 1 1 1
1.00100502512563 1.00100502512563 1.00100502512563 1.00100502512563 1.00100502512563
1.00201005025126 1.00201005025126 1.00201005025126 1.00201005025126 1.00201005025126
1.00301507537688 1.00301507537688 1.00301507537688 1.00301507537688 1.00301507537688
1.00402010050251 1.00402010050251 1.00402010050251 1.00402010050251 1.00402010050251
1.00502512562814 1.00502512562814 1.00502512562814 1.00502512562814 1.00502512562814
1.00603015075377 1.00603015075377 1.00603015075377 1.00603015075377 1.00603015075377
1.00703517587940 1.00703517587940 1.00703517587940 1.00703517587940 1.00703517587940
1.00804020100503 1.00804020100503 1.00804020100503 1.00804020100503 1.00804020100503
1.00904522613065 1.00904522613065 1.00904522613065 1.00904522613065 1.00904522613065
1.01005025125628 1.01005025125628 1.01005025125628 1.01005025125628 1.01005025125628
1.01105527638191 1.01105527638191 1.01105527638191 1.01105527638191 1.01105527638191
1.01206030150754 1.01206030150754 1.01206030150754 1.01206030150754 1.01206030150754
1.01306532663317 1.01306532663317 1.01306532663317 1.01306532663317 1.01306532663317
1.01407035175879 1.01407035175879 1.01407035175879 1.01407035175879 1.01407035175879
1.01507537688442 1.01507537688442 1.01507537688442 1.01507537688442 1.01507537688442
1.01608040201005 1.01608040201005 1.01608040201005 1.01608040201005 1.01608040201005
1.01708542713568 1.01708542713568 1.01708542713568 1.01708542713568 1.01708542713568
1.01809045226131 .01809045226131  1.01809045226131 1.01809045226131 1.01809045226131
1.01909547738693 1.01909547738693 1.01909547738693 1.01909547738693 1.01909547738693];

Z=[0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000
0.0500000000000000 0.100000000000000 0.150000000000000 0.200000000000000 0.250000000000000];

Please notice how Z is constant for each column

share|improve this question
    
Can you provide 5-10 lines of your data for understanding how it looks like? Feels possible with pgfplots –  percusse Oct 14 '13 at 14:09
    
@percusse , I don't know if this is enough: X=[0 0 0 0.0144 0.0742 0.1640 0.02 0. 1025 0.2243]; Y=[1 1 1 1.009 1.009 1.009 1.0191 1.0191 1.0191]; Z=[0.05 0.25 0.5] Can send you a *.mat file also, but I think it is not possible in here –  user2536125 Oct 14 '13 at 14:47
    
You can copy the text from matlab screen and paste it into your question. If you select the numbers and click the {} button it will show it as a code block. You can edit your question by clicking the edit link under the question. –  percusse Oct 14 '13 at 15:00
    
{X=0 0 0 0,00499487214258387 0,0100271322719341 0,0151355841667174 0,00703013931750997 0,0141123715001326 0,0213007419561194 0,00856912164753604 0,0172011015018718 0,0259611298569260 0,00984769541100846 0,0197669024060679 0,0298317587516411}, {Y=[1 1 1 1,00100502512563 1,00100502512563 1,00100502512563 1,00201005025126 1,00201005025126 1,00201005025126 1,00301507537688 1,00301507537688 1,00301507537688 1,00402010050251 1,00402010050251 1,00402010050251 ]}, {Z=[0.5 0.1 0.15]} –  user2536125 Oct 14 '13 at 15:12
    
Emphasis on the edit link under your question not the comment box. –  percusse Oct 14 '13 at 15:21

2 Answers 2

up vote 3 down vote accepted

You can use contour plot. First, prepare the data in MATLAB:

[reshape(X,[],1), reshape(Y,[],1), reshape(Z,[],1)];

Then, you can use the data in TeX:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xticklabel style={/pgf/number format/.cd, fixed, precision=2},
        yticklabel style={/pgf/number format/.cd, fixed, precision=3},
        ]
        \addplot[
            colormap={onlyblack}{gray(0cm)=(0); gray(1cm)=(0)},
            contour prepared,
            contour/contour label style={/pgf/number format/.cd, fixed, precision=2},
            contour/label distance={1000pt}, % use big number to get one label per contour
            ] table {
            0   1   0.05
            0.00499487214258387 1.00100502512563    0.05
            0.00703013931750997 1.00201005025126    0.05
            0.00856912164753604 1.00301507537688    0.05
            0.00984769541100846 1.00402010050251    0.05
            0.0109577332470996  1.00502512562814    0.05
            0.0119466084732432  1.00603015075377    0.05
            0.0128426154484001  1.00703517587940    0.05
            0.0136642899493110  1.00804020100503    0.05
            0.0144245776620953  1.00904522613065    0.05
            0.0151329564382696  1.01005025125628    0.05
            0.0157966212085941  1.01105527638191    0.05
            0.0164211931300526  1.01206030150754    0.05
            0.0170111676966756  1.01306532663317    0.05
            0.0175702105696051  1.01407035175879    0.05
            0.0181013600452389  1.01507537688442    0.05
            0.0186071698801841  1.01608040201005    0.05
            0.0190898126701751  1.01708542713568    0.05
            0.0195511563564558  1.01809045226131    0.05
            0.0199928219502558  1.01909547738693    0.05
            0   1   0.10
            0.0100271322719341  1.00100502512563    0.10
            0.0141123715001326  1.00201005025126    0.10
            0.0172011015018718  1.00301507537688    0.10
            0.0197669024060679  1.00402010050251    0.10
            0.0219942405774403  1.00502512562814    0.10
            0.0239782392419037  1.00603015075377    0.10
            0.0257757149277838  1.00703517587940    0.10
            0.0274238903416811  1.00804020100503    0.10
            0.0289487637697525  1.00904522613065    0.10
            0.0303693701768318  1.01005025125628    0.10
            0.0317001603416950  1.01105527638191    0.10
            0.0329524247496926  1.01206030150754    0.10
            0.0341351933703888  1.01306532663317    0.10
            0.0352558296774944  1.01407035175879    0.10
            0.0363204372087640  1.01507537688442    0.10
            0.0373341463673818  1.01608040201005    0.10
            0.0383013220178056  1.01708542713568    0.10
            0.0392257171221451  1.01809045226131    0.10
            0.0401105886622858  1.01909547738693    0.10
            0   1   0.15
            0.0151355841667174  1.00100502512563    0.15
            0.0213007419561194  1.00201005025126    0.15
            0.0259611298569260  1.00301507537688    0.15
            0.0298317587516411  1.00402010050251    0.15
            0.0331911596116199  1.00502512562814    0.15
            0.0361829739474490  1.00603015075377    0.15
            0.0388930053871466  1.00703517587940    0.15
            0.0413774721254582  1.00804020100503    0.15
            0.0436756433487295  1.00904522613065    0.15
            0.0458162730087464  1.01005025125628    0.15
            0.0478211921655991  1.01105527638191    0.15
            0.0497074590478197  1.01206030150754    0.15
            0.0514887177522871  1.01306532663317    0.15
            0.0531760952694321  1.01407035175879    0.15
            0.0547788154484420  1.01507537688442    0.15
            0.0563046321253931  1.01608040201005    0.15
            0.0577601426467341  1.01708542713568    0.15
            0.0591510199088859  1.01809045226131    0.15
            0.0604821874442227  1.01909547738693    0.15
            0   1   0.20
            0.0203619904285679  1.00100502512563    0.20
            0.0286533748405864  1.00201005025126    0.20
            0.0349192664533911  1.00301507537688    0.20
            0.0401218833508729  1.00402010050251    0.20
            0.0446361019206510  1.00502512562814    0.20
            0.0486552739640120  1.00603015075377    0.20
            0.0522949117805015  1.00703517587940    0.20
            0.0556307081325855  1.00804020100503    0.20
            0.0587155421791397  1.00904522613065    0.20
            0.0615881383770832  1.01005025125628    0.20
            0.0642779014739504  1.01105527638191    0.20
            0.0668078104510510  1.01206030150754    0.20
            0.0691962474012896  1.01306532663317    0.20
            0.0714582050315404  1.01407035175879    0.20
            0.0736061131758165  1.01507537688442    0.20
            0.0756504218986758  1.01608040201005    0.20
            0.0776000236025984  1.01708542713568    0.20
            0.0794625654482437  1.01809045226131    0.20
            0.0812446851052654  1.01909547738693    0.20
            0   1   0.25
            0.0257528910437245  1.00100502512563    0.25
            0.0362349750090093  1.00201005025126    0.25
            0.0441534216317338  1.00301507537688    0.25
            0.0507257254049430  1.00402010050251    0.25
            0.0564262963381876  1.00502512562814    0.25
            0.0614998638245181  1.00603015075377    0.25
            0.0660926587477192  1.00703517587940    0.25
            0.0703005193527485  1.00804020100503    0.25
            0.0741904098771546  1.00904522613065    0.25
            0.0778113778863288  1.01005025125628    0.25
            0.0812006730740997  1.01105527638191    0.25
            0.0843874098612964  1.01206030150754    0.25
            0.0873948821954542  1.01306532663317    0.25
            0.0902420919849960  1.01407035175879    0.25
            0.0929447953582426  1.01507537688442    0.25
            0.0955162408504069  1.01608040201005    0.25
            0.0979677038151599  1.01708542713568    0.25
            0.100308881996065   1.01809045226131    0.25
            0.102548194045946   1.01909547738693    0.25
        };
    \end{axis}
\end{tikzpicture}
\end{document}

This results in the following plot:

result

Note: I have assumed a typo and changed one of your points from .01809045226131 to 1.01809045226131.

share|improve this answer
    
Very nice! For getting black lines and labels, you can use contour/draw color=black, contour/contour label style={/tikz/every node/.append style={text=black}} –  Jake Oct 15 '13 at 15:19
    
@PiotrWydrych ....Perfect! –  user2536125 Oct 15 '13 at 15:40

If you use the package matlab2tikz provided by Mathworks to export the most recent plot to an arbitrary file name:

matlab2tikz('my3d_plot.tikz');

Keep in mind that you have to download this function (and keep it in the active folder for evaluation). Furthermore this function produces for each plot a file called my3d_plot-n.png where n stands for the n'th plot/subplot.

3D plot

Use for instance the matlab plot function

imagesc(DATA);
colorbar('location','southoutside')

where the function has the options to set the color-limits and color-theme. These options are well described also at mathworks's homepage.

Save file

Save the file 'my3d_plot.tikz' in the same directory as your processed latex-file because otherwise the paths inside the file my3d_plot.tikz refer to the wrong directory.

Latex file

Something like the following MWE should make it:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{graphicx}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}
\input{my3d_plot.tikz}
\end{document}

Did this answer your question or was the question about another feature to plot?

share|improve this answer
    
,,,,Thanks for the answer, however, this is not really what I am looking for. If you look at the attached figure, you will notice it is a 3D plot, however, the third dimension (z) is constant for each line...In matlab, one can use different colors, to specify Z, however, I am not allowed to use colors for my plot, thus, I think the best way to do that is as shown in the attached figure. –  user2536125 Oct 14 '13 at 15:14
    
So you might want to use gray color scale with the command colormap(gray). See mathworks.com/help/matlab/ref/colormap.html –  strpeter Oct 14 '13 at 15:19
1  
@strpeter: Or use a contour plot –  Jake Oct 14 '13 at 15:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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