in this video we will learn how to make bar graphs in scilab
so bar graphs are very important when you are comparing a data over a longer
period of time a relatively longer period of time for example for a few
months so here we have a data for a hospital in which three childhood
diseases we have and this data was collected for the six-month of any year
we have data from January to June for these three diseases so number of cases
for each disease which were brought to the hospital so there are two types of
bar graphs one are called grouped bar graphs in which for example for January
we will see three bars for these three diseases
similarly for February we will see these three bar for these three diseases
separately and then stacked bar graphs in which for every month we will have
one bar graph in which there will be three portions for this according to the
size of this data so let's see how we can make these graphs so this is our
Scilab so the best practice is to start script for this so I am launching this
side nodes which is the default editor
so I'll just type it here so first on our x-axis we have months so I will take
up matrix a you can see a vector for months so months equal and it's just six
values vector six entries so this is our months vector and for diseases we take a
matrix with the name diseases which is equal to so now I will just type
automatics because it will waste the times I will fast forward the video I
will just put the entries here so now we have made these two matrices for months
we have one two six at a distance of 1 so 1 : 1 : 6
and our diseases we have this matrix so because there are three diseases so
after three entries we have a semicolon then the next three for the next month
and then a semicolon on six times so now we have both values and now we are ready
to make the bar graph so the command is very simple which is bar and then you
can put months coma diseases and now you can run this program save and execute
and as you can see that it has shown us the bar graph for these diseases know
for every month we have three diseases for the second month and third month so
three different colors so this is called group arrangement so there are two types
of options we have one is a group and the other is stacked and in order to
give that option the stacked one we have to use this command with a third with a
comma because if we don't use this comma then it's taking the default option
which is the group top chain so then you can here type in a single quotation
marks tagged and now it will show you the stack graph run it again save and
execute and now as you can see that now we have the stag option in which three
diseases are stacked on top of each other so because we have not decided the
previous figure so therefore you can see on the back so I just close this window
and run it again and now you can see that we don't have that previous figure
because if you don't close this so it will draw the graph on the same figure
and now we have this tagged option and this looks better and know for example
if you want to give a title of this graph and also
axel Abel and also a wine label so in order to do that let's say we want to
put months here diseases here and here we want to put let's say childhood data
for three childhood diseases as a graph title so we can do this all this in a
single command you can do this separately like title and X title but
you can use only the X title command and an X title command you can handle all
these three I mean X label Y label and the graph title so first you put the
graph title within the double quotation marks and for example our title is a
data for three childhood diseases this is our graph title and let's say where X
label is so we have to put a comma and then again double quotation marks and
our X level is months you can put two thousand let's say 17 for example and
then on the y axis you can have diseases or disease cases so these are our labels
X label Y label and the title of the graph run it again and now we have as
you can see here let me bring this on top as you can see we have the title of
the graph X label and the Y label now let's say that we want to put legions
here because there are three diseases so we want to put their name here so in
order to do that we can use a command which is called Legion so
reject and you can assign any vector any variable if you want for example h1 or
something agent and then you start this parenthesis and the parenthesis you
start this a matrix symbol and then in this you can put three disease names so
because these are string values so you have to put this inter quotation or
double quotation so the first is chickenpox and then you have to put a
semicolon because we have three entries here then again single quotation mark
and mumps in semicolon start the string again and measles so these are the three
values for our legions no we run it again and as you can see that our
legions are here this is not looking good it's obstructing our graph so there
are a couple of options which you can see somewhere in the manual or I will
put somewhere in in a chart so those position values you can assign
for example three value two values so you can assign some position values
based on those position value you can put in the left-right corners are
somewhere there but the best way which I normally want to use is that I want to
put this at my own choice wherever I want so for that we have to use the
option number five so in this region command you can put a comma here and
then you can take any variable so equals pause equals five so this is the
position variable so five is the value five when you put five so it will allow
you to put this legend this box anywhere you want so when I run this know here as
you can see that it is it is allowing me to put this legend anywhere I want so
this is the best here so I will just put it so this is
how you put the religion now these months are the values 1 2 3 4 5 6 so if
you want to put some January February like these so then you have to do this
with the advanced properties of axis so you can get access to those properties
by taking a handle and what is a handle and L is a identifier for this diagram
for this figure so that is called a handle so you first get the handle in a
variable and then with the help of that variable you get access to the property
for example this stick this stick is called X ticks so these are X takes X
take extra extreme so we have this property which is called X underscore
tics and then 1 2 3 what is written here this is the property which is called X
takes dot labels so you have to access that property and then you can modify
the value of those ticks labels and this is what we are going to do next how to
change these two I will make another video for advanced graphics but because
we are doing this bar graph so I want to finish this off so after this nothing is
left then you can make any bar graph so therefore I want to cover this in this
video as well so it is a little bit of advanced topic so if you don't
understand anything so there will be a separate video for advanced graphics so
that there I will explain this again so now just quickly how to do this in order
to get access to the handle of this figure we have the command GCS if it's a
function so we want to store that value in a variable so let's say a is a
variable and we say GC a get get current axis this will give us access to the
axis properties and we have saved this in a variable a
and now we will manipulate property which is called X ticks dot labels which
is this one one two three four five six written there so instead of that we want
to write some other strings so we will write for example January JN then we
have to put a semicolon because this is the first entry then February and then a
semicolon then we put our March semicolon APR 7 1 and then Ju so now we
want to use these six values for our x ticks labels so this is how we do that
now we run it again as you can know I have put it here but anyway as you can
see that now we have these labels so this is it I hope that this will help
you make any types of bar graphs
Không có nhận xét nào:
Đăng nhận xét