How to plot like matlab routine surf(X,Y,Z)?

88 views
Skip to first unread message

Shannon Chow

unread,
Nov 14, 2017, 7:41:57 AM11/14/17
to MathGL


The X\Y\Z data were contained in the *csv files attached. I can easily draw this by matlab routine surf(X,Y,Z) and the results were as follows:

Figure 1. Matlab Surf plot


 Both X and Y were vectors in matlab and the values were logarithmically spaced . In Matlab, X equals Y.


I want to draw it using mathgl. now. I tried a period of time but still not got a good result similar to matlab. Up till now, my best results were as follows:

Figure My trials using mathgl

Source code (in source.txt)  was also attached. Any one can help to modify the code to drawing a figure similar to Figure 1?

Any ideas will be appreciated!

mgl-sln.zip

Alexey Balakin

unread,
Nov 14, 2017, 3:22:26 PM11/14/17
to mat...@googlegroups.com
Dear Shannon,

I think that main yours mistake is using lighting. Because yours surface is mostly flat, and light just produce the "white" reflection mostly everywhere.

The MGL sample code is

#first read files
read T 'T.csv'
read S 'S.csv'
# ===== next setup plot =====
setsize 800 600
# adjust plot size (reserve place at left, right and bottom only)
subplot 1 1 0 '<_>'
# set axis ranges
ranges T T S
# set logarithmic axis for x and y
axis 'lg(x)' 'lg(y)' '' ''
# ===+= now start drawing ======
# draw surface
# here I use color scheme 'Bn{q7}y', which is similar to one in yours Matlab image
surf T T S 'Bn{q7}y'
# draw axis (style 'U' for unrotated labels) and bounding box
axis 'U':box
# draw colorbar with the same color scheme
colorbar 'Bn{q7}y'
# axis labels (option "value" additionally shift the label -- needed due to using unrotated labels)
xlabel '\i T_2/(ms)' 0
ylabel '\i T_1/(ms)' 0;value 0.1


The corresponding C++ code is

int sample(mglGraph *gr)
{
    mglData T("T.csv"), S("S.csv");
    gr->SetSize(800, 600);
    gr->SubPlot(1,1,0,"<_>");
    gr->SetRanges(T,T,S);
    gr->SetFunc("lg(x)", "lg(y)","");
    // ===============
    gr->Axis("U");    gr->Box();
    gr->Label('x', "\\i T_2/(ms)",0);
    gr->Label('y', "\\i T_1/(ms)",0,"value 0.1");
    gr->Surf(T, T, S, "Bn{q7}y");
    gr->Colorbar("Bn{q7}y");
    gr->WriteBMP("sample.bmp");
    return 0;
}

The resulting image is attached.



14.11.2017 12:16, Shannon Chow пишет:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Kind regards,
Alexey Balakin
mgl-sin.png

Shannon Chow

unread,
Nov 14, 2017, 8:38:32 PM11/14/17
to MathGL
Thank you very much! This works well for me.

在 2017年11月15日星期三 UTC+8上午4:22:26,Alexey Balakin写道:
Reply all
Reply to author
Forward
0 new messages