# Various embellishments on a plot

**URL:** <https://scilab.discourse.group/t/various-embellishments-on-a-plot/539>\
**Category:** Graphics and plotting\
**Created:** [June 5, 2024, 3:09pm UTC](https://scilab.discourse.group/t/various-embellishments-on-a-plot/539 "2024-06-05T15:09:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pascal77](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@Pascal77](https://scilab.discourse.group/u/Pascal77)\
**Post date:** [June 5, 2024, 3:09pm UTC](https://scilab.discourse.group/t/various-embellishments-on-a-plot/539/1 "2024-06-05T15:09:03Z")

</div>

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:

```auto
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)

```

 ![Basic plot](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/19c74befcb22da14d998dd5809dc4fbf7f5ab421.png)

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

```auto
// 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

```

 ![Improved plot with post_tunig Axes and Curves](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/0bf4b07869a78a0f20c610fdb07bcc8168d1fdbb.png)

---

<div class="post-metadata">

**Author:** ![Pascal77](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@Pascal77](https://scilab.discourse.group/u/Pascal77)\
**Post date:** [June 7, 2024, 11:04am UTC](https://scilab.discourse.group/t/various-embellishments-on-a-plot/539/2 "2024-06-07T11:04:23Z")

</div>

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

The code:

```auto
//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;

```

 ![2024-06-07 12_56_50-improved plot2d example](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/8a33d497b2bd36d52717169a03569fc028763d70.png)

---

<div class="post-metadata">

**Author:** ![mario](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mario/32/396_2.png) [@mario](https://scilab.discourse.group/u/mario)\
**Post date:** [June 10, 2024, 7:05am UTC](https://scilab.discourse.group/t/various-embellishments-on-a-plot/539/3 "2024-06-10T07:05:28Z")

</div>

Very useful.  
Thank you. 👍
