Search code examples
plotscilab

Scilab - How to plot numbers v string


Say I have been tracking my weight each month (on and off for a couple of years), and I want to plot the data, such that:

  • the x-axis represents the time. e.g. Jun 2015, Jul 2015, Aug 2015, Sept 2015.
  • the y-axis represents the weights. e.g. 75.4, 75.1, 72.6, 71.6

I thought this could be achieved by simply writing:

x = ["Jun 2015", "Jul 2015", "Aug 2015", "Sept 2015"];
y = [75.4, 75.1, 72.6, 71.6];

plot(x,y);

But this produces an error. How can I approach this?

And on a related note: How can I have a break in the x-axis? Say that I did not weigh myself on some months, and so I want a break in the x-axis to indicate that.


Solution

  • You can use the axes entities to do that:

       n=size(y,"*");
       plot(1:n,y)
       ax=gca();
       x_ticks=ax.x_ticks;
       x_ticks.locations=1:n;
       x_ticks.labels=x;
       ax.x_ticks=x_ticks;