Various embellishments on a plot

Native plots are not attractive enough to put them into a document or a report.
You will find below some tricks to improve the graphic rendering of figures.

First, you will find a basic plot:

clf;//clear previous existing figures

//Plot the curves-------------------------------------------------------------
//The following 3 lines are enough to draw the curve itself. 
//They are the minimum necessary.

x=[0:0.1:2*%pi]';
plot(x-4,sin(x), x+2,cos(x))
xgrid(2,1,7);//xgrid(color, thickness, style)

Now, let’s move on to the enhanced graphic:

// Various embellishments on a plot
//---------------------------------

clf;//clear previous existing figures


//Plot the curves-------------------------------------------------------------
//The following 3 lines are enough to draw the curve itself. 
//They are the minimum necessary.

x=[0:0.1:2*%pi]';
plot(x-4,sin(x), x+2,cos(x))
xgrid(2,1,7);//xgrid(color, thickness, style)

//============================================================================
//All the lines that follow will enable you to embellish the graphic, 
//personalize it, make it more readable, 
//or even more attractive for incorporation into a document.

//Figure definition-----------------------------------------------------------
f=gcf();
f.background=color('gray50');// or any other predefined color name (in color_list)
f.figure_size=[1000,800];
f.figure_name='Post_tunig Axes and Curves';


//Axis definition-------------------------------------------------------------
a=gca(); // Handle on axes entity
a.x_location = "origin";// axis centered at (0,0)
a.y_location = "origin";// axis centered at (0,0)
a.thickness=2;
a.foreground=color('yellow');// color of the axis and box
a.background=color('gray80');// or any other predefined color name (in color_list)

//Customized axis label-------------------------------------------------------
//x axis
xstring(9.0,0.01,'time-->');
t1 = gce();   // get the handle of the newly created object
t1.font_foreground=7; // change font properties
t1.font_size=3;
t1.font_style=9;

//y axis
xstring(0.4,0.75,'curves-->',270);
t1 = gce();   // get the handle of the newly created object
t1.font_foreground=7; // change font properties
t1.font_size=3;
t1.font_style=9;

// Some additionnal improvements ...-------------------------------------------
isoview on
a.children // list the children of the axes : 
//here we have a set of child composed of 2 entities : curve 1 and curve 2

//first curve
poly1= a.children.children(1); //store polyline handle into poly1
poly1.foreground = 2;  // change the color...
poly1.thickness = 2;   // ...and the thickness of a curve.
poly1.clip_state='off' // clipping control

//identifying the curve 1 on the plot
xstring(5,0.8,'curve 1')//identifying the curve 1 on the plot
t1 = gce();   // get the handle of the newly created object
t1.font_foreground=2; // change font properties
t1.font_size=3;
t1.font_style=9;

//second curve
poly2= a.children.children(2); //store polyline handle into poly2
poly2.foreground = 5;  // change the color...
poly2.thickness = 4;   // ...and the thickness of a curve.
poly2.clip_state='off' // clipping control

//identifying the curve 2 on the plot
xstring(-3.3,0.4,'curve 2')//identifying the curve 2 on the plot
t2 = gce();   // get the handle of the newly created object
t2.font_foreground=5; // change font properties
t2.font_size=3;
t2.font_style=9;

//Adding a plot legend---------------------------------------------------------
legend("sin(x)","cos(x)",4);
t3 = gce();   // get the handle of the newly created object
t3.font_foreground=1; // change font properties
t3.font_size=3;
t3.font_style=9;

//Adding a general title of the plot-------------------------------------------
title('my title','font_style',5,'color','green','edgecolor','yellow','backgroundcolor','peru','fontsize',5,'rotation',00,'position',[1.8 1]);


isoview off

Below is a variant of my previous example, this time with plot2d instruction for plotting curves.

The code:

//plot2d example with improved axis rendering

clf();//clear all previous figures

//basic plotting
x=[-10:0.1:10];//(xmin,step,xmax)
plot2d(x,sin(x),5);//curve 1
plot2d(x,cos(x),5);//curve 2
xgrid(2,1,8);//xgrid(color, thickness, style)

//setting background color and size of the figure itself
fig=gcf();
fig.background=color('gray60');//bkgrd color (surrounding the plot)
fig.figure_size=[1000,800];//size


//legend improvements
hl=legend(['sin(x)';'cos(x)'],-1);//defining legend
e=gce();//improvements on legend
e.font_foreground=2; // change font color blue = 2 in basic color map
e.font_size=3;
e.font_style=9;//helvetica bold italic

//General title (centered by default)
title('plot2d example with improved axis rendering');
title font_style 9;//helvetica bold italic
title color blue;
title font_size 3;
title edgecolor blue;
title backgroundcolor gray50;


//setting axis improvements
a=gca(); // Handle on axes entity
a.x_location = "origin"; // axis centered at (0,0) 
a.y_location = "origin"; // axis centered at (0,0) 
a.foreground=color('blue');//set axis lines colors (defined in color_list)
a.thickness=2;//define the thickness of the axis lines
a.background=color('gray50');//define the background color of the plot himself
a.box="on";//figure is "boxed"

//setting curve 1 improvements
curve1=a.children.children(1);//set curve appearance
curve1.foreground=color('yellow');//curve color
curve1.thickness=2;//curve thickness

//setting curve 2 improvements
curve2=a.children.children(2);//set curve appearance
curve2.foreground=color('red');//curve color
curve2.thickness=2;//curve thickness

//Customized axis label-------------------------------------------------------
//x axis
xstring(7.0,0.01,'time-->');
t1 = gce();   // get the handle of the newly created object
t1.font_foreground=7; // change font properties
t1.font_size=3;
t1.font_style=9;

//y axis
xstring(0.8,0.6,'curve-->',270);//text is 270° turned (vertical)
t2 = gce();   // get the handle of the newly created object
t2.font_foreground=7; // change font properties
t2.font_size=3;
t2.font_style=9;

Very useful.
Thank you. :+1:

1 Like