Difference between revisions of "Python-3.4.3/C2/Embellishing-a-plot/English"
Nancyvarkey (Talk | contribs) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
'''Title of script''': '''Embellishing a Plot''' | '''Title of script''': '''Embellishing a Plot''' | ||
− | '''Author: ''' | + | '''Author: ''' Pravin,''' '''Aditya Palaparthy''' |
'''Keywords: Python, IPython,''' '''plot, title''' | '''Keywords: Python, IPython,''' '''plot, title''' | ||
− | |||
Line 22: | Line 21: | ||
Objectives | Objectives | ||
− | |||
− | |||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| At the end of this tutorial, we will learn to- | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| At the end of this tutorial, we will learn to- | ||
− | |||
# Modify the attributes of the '''plot''' -- '''color''', '''line style''', '''linewidth'''. | # Modify the attributes of the '''plot''' -- '''color''', '''line style''', '''linewidth'''. | ||
Line 33: | Line 29: | ||
# Add annotations to the '''plot'''. | # Add annotations to the '''plot'''. | ||
# Set and get the '''limits '''of '''axes'''. | # Set and get the '''limits '''of '''axes'''. | ||
− | |||
− | |||
|- | |- | ||
Line 45: | Line 39: | ||
* '''Python 3.4.3''' | * '''Python 3.4.3''' | ||
* '''IPython 5.1.0''' | * '''IPython 5.1.0''' | ||
− | |||
− | |||
|- | |- | ||
Line 64: | Line 56: | ||
'''ipython3 '''and press '''Enter.''' | '''ipython3 '''and press '''Enter.''' | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Let us start '''ipython3'''. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Let us start '''ipython3'''. | ||
− | |||
Open the '''terminal.''' | Open the '''terminal.''' | ||
− | |||
Type '''ipython3 '''and press '''Enter.''' | Type '''ipython3 '''and press '''Enter.''' | ||
Line 75: | Line 65: | ||
'''%pylab '''and press '''Enter.''' | '''%pylab '''and press '''Enter.''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Let us initialise the pylab package | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Let us initialise the '''pylab package''' |
− | + | Type '''percentage pylab '''and press''' Enter.''' | |
− | Type ''' | + | |
|- | |- | ||
Line 87: | Line 76: | ||
− | Type '''x = linspace inside the brackets minus 2 comma 4 comma 20 '''and press '''Enter.''' | + | Type '''x = linspace''' inside the '''brackets minus 2 comma 4 comma 20 '''and press '''Enter.''' |
|- | |- | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| '''plot(x, sin(x)) '''and press '''Enter.''' | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| '''plot(x, sin(x)) '''and press '''Enter.''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Then type ''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Then type '''plot''' inside the '''brackets x comma sin(x) '''and press '''Enter.''' |
|- | |- | ||
Line 121: | Line 110: | ||
'''plot(x, sin(x), 'r') '''and press '''Enter.''' | '''plot(x, sin(x), 'r') '''and press '''Enter.''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now '''plot''' the same '''sine curve '''with an additional '''color | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now '''plot''' the same '''sine curve '''with an additional '''color argument'''. |
− | So we will type '''plot inside the brackets x comma sin(x) comma inside inverted | + | So we will type '''plot''' inside the '''brackets x comma sin(x) comma''' inside '''inverted commas r '''and press '''Enter.''' |
Here, the '''argument 'r' '''is for red color. | Here, the '''argument 'r' '''is for red color. | ||
Line 150: | Line 139: | ||
− | So, type '''plot inside the brackets x comma cos(x) comma linewidth equals to 2 '''and press '''Enter.''' | + | So, type '''plot''' inside the '''brackets x comma cos(x) comma linewidth equals to 2 '''and press '''Enter.''' |
|- | |- | ||
Line 164: | Line 153: | ||
|- | |- | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [IPython console] | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| [IPython console] | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Here onwards, press the '''Enter''' the key to execute every command that we type on the '''Ipython console'''. | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Here onwards, |
+ | *press the '''Enter''' the key to execute every command | ||
+ | *that we type on the '''Ipython console'''. | ||
|- | |- | ||
Line 172: | Line 163: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| First let us clear the '''plot '''window by typing '''clf(). ''' | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| First let us clear the '''plot '''window by typing '''clf(). ''' | ||
− | You will again see a blank plot window | + | You will again see a blank plot window. |
|- | |- | ||
Line 178: | Line 169: | ||
'''plot(x, sin(x), 'b', linewidth=3)''' | '''plot(x, sin(x), 'b', linewidth=3)''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now type''' inside the brackets | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now type''' plot''' inside the '''brackets x comma sin(x) comma''' inside '''inverted commas b comma linewidth equals to 3''' |
Line 199: | Line 190: | ||
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now type '''plot''' inside the '''brackets x comma sin(x) comma''' inside '''inverted commas dot.''' | |
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now type '''plot inside the brackets | + | |
|- | |- | ||
Line 229: | Line 219: | ||
− | '''Plot''' the '''curve''' of '''x | + | '''Plot''' the '''curve''' of '''x verses cos(x)''' in red '''dash line''' and '''linewidth''' 3. |
|- | |- | ||
Line 248: | Line 238: | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now type '''plot inisde brackets x comma cos(x) comma inside inverted commas r hypen hypen comma linewidth equals to 3''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now type '''plot''' inisde '''brackets x comma cos(x) comma''' inside '''inverted commas r hypen hypen comma linewidth equals to 3''' |
− | We use a combination of '''linewidth | + | We use a combination of '''linewidth argument''' and '''linestyle'''. |
|- | |- | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now we know how to produce a '''bare minimum plot''' with '''color | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Now we know how to produce a '''bare minimum plot''' with '''color, style''' and '''thickness'''. |
Line 264: | Line 254: | ||
'''plot(x, -x*x + 4*x - 5, 'r', linewidth=2) ''' | '''plot(x, -x*x + 4*x - 5, 'r', linewidth=2) ''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Let us start with a '''plot''' for the '''function | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Let us start with a '''plot''' for the '''function minus x square plus 4x minus 5. ''' |
− | Now type '''plot inside brackets x comma minus x multiplied by x plus 4 multiplied by x minus 5 comma | + | Now type '''plot''' inside the '''brackets x comma minus x multiplied by x plus 4 multiplied by x minus 5 comma''' inside '''inverted commas r comma linewidth equals to 2''' |
|- | |- | ||
Line 280: | Line 270: | ||
'''title("Parabolic function -x^2+4x-5")''' | '''title("Parabolic function -x^2+4x-5")''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To add a title to the '''plot''', use the '''title | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| To add a title to the '''plot''', use the '''title command'''. |
− | So type '''title inside the brackets inside inverted commas Parabolic function minus x square plus 4x minus 5''' | + | So type '''title''' inside the '''brackets''' inside '''inverted commas Parabolic function minus x square plus 4x minus 5''' |
|- | |- | ||
Line 289: | Line 279: | ||
Highlight the '''title '''command | Highlight the '''title '''command | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The '''title''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The '''title command''' as you can see, takes a '''string''' as an '''argument.''' |
|- | |- | ||
Line 309: | Line 299: | ||
'''title(r"Parabolic function $-x^2+4x-5$") ''' | '''title(r"Parabolic function $-x^2+4x-5$") ''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| For '''LaTeX''' format, we put a ''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| For '''LaTeX''' format, we put a '''dollar sign '''before and after the '''string'''. |
− | Type '''title inside the brackets r inside inverted commas Parabolic function dollar minus x square plus 4x minus 5''' | + | Type '''title''' inside the '''brackets r''' inside '''inverted commas Parabolic function dollar minus x square plus 4x minus 5 dollar''' |
Line 333: | Line 323: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Although we have '''title''', the '''plot''' is not complete without labelling the '''x '''and '''y axes'''. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Although we have '''title''', the '''plot''' is not complete without labelling the '''x '''and '''y axes'''. | ||
− | So we will '''label | + | So we will '''label x''' and '''y axes''' in '''LaTeX style'''. |
− | Type '''xlabel inside the brackets r | + | Type '''xlabel''' inside the '''brackets r''' inside '''inverted commas dollar x dollar '''and''' ylabel''' inside '''brackets r''' inside '''inverted commas dollar y dollar ''' |
|- | |- | ||
Line 349: | Line 339: | ||
− | Now we will name the '''points''' considering '''point(2 | + | Now we will name the '''points''' considering '''point(2 comma minus 1)''' as '''local maxima'''. |
− | To name a '''point''' we use the '''function | + | To name a '''point,''' we use the '''function annotate'''. |
− | Type '''annotate inside the brackets | + | Type '''annotate''' inside the '''brackets''' inside '''inverted commas local maxima comma xy equals to''' inside '''brackets 2 comma minus 1''' |
|- | |- | ||
Line 362: | Line 352: | ||
Show the annotation that has appeared on the plot | Show the annotation that has appeared on the plot | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| We can see the '''local maxima''' at point '''(2 | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| We can see the '''local maxima''' at point '''(2 comma minus 1)''' |
|- | |- | ||
Line 369: | Line 359: | ||
Point at the annotate command while explaining | Point at the annotate command while explaining | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The first '''argument''' in '''annotate''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| The first '''argument''' in '''annotate command''' is the name of the point. |
− | The second '''argument''' represents the '''coordinates '''of | + | The second '''argument''' represents the '''coordinates '''of the '''point'''. |
Line 399: | Line 389: | ||
'''ylim(-15, 2)''' | '''ylim(-15, 2)''' | ||
− | | style="background-color:#ffffff;border-top:none;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Set the '''limits of x-axis''' from | + | | style="background-color:#ffffff;border-top:none;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Set the '''limits of x-axis''' from '''minus''' 4 to 5 by typing '''xlim inside the brackets minus 4 comma 5''' |
Line 405: | Line 395: | ||
− | Type '''ylim inside the brackets minus 15 comma 2.''' | + | Type '''ylim''' inside the '''brackets minus 15 comma 2.''' |
|- | |- | ||
Line 417: | Line 407: | ||
− | Make an '''annotation''' called "'''root'''" at the '''point ( | + | Make an '''annotation''' called "'''root'''" at the '''point (minus 4 comma 0)'''. |
What happens to the first '''annotation'''? | What happens to the first '''annotation'''? | ||
Line 432: | Line 422: | ||
− | Type '''annotate inside brackets | + | Type '''annotate''' inside the '''brackets''' inside '''inverted commas root comma xy equals to''' inside '''brackets minus 4 comma 0''' |
− | Every '''annotate | + | Every '''annotate command''' makes a new '''annotation''' on the figure. |
|- | |- | ||
Line 447: | Line 437: | ||
− | # Modify the '''attributes''' of a '''plot''' like '''color | + | # Modify the '''attributes''' of a '''plot''' like '''color, line width, line style''' by passing additional '''arguments'''. |
− | # Add '''title '''to a '''plot''' using ''''title | + | # Add '''title '''to a '''plot''' using ''''title command'''. |
# Incorporate '''LaTeX style formatting''' by adding a $ sign before and after the '''string'''. | # Incorporate '''LaTeX style formatting''' by adding a $ sign before and after the '''string'''. | ||
− | # Label '''x and y axes''' using '''xlabel()''' and '''ylabel() | + | # Label '''x''' and '''y axes''' using '''xlabel()''' and '''ylabel() commands'''. |
− | # Add '''annotations''' to a plot using '''annotate() | + | # Add '''annotations''' to a plot using '''annotate() command'''. |
− | # Get and set the '''limits of axes''' using '''xlim()''' and '''ylim() | + | # Get and set the '''limits of axes''' using '''xlim()''' and '''ylim() commands. ''' |
− | + | ||
Line 460: | Line 449: | ||
Evaluation | Evaluation | ||
− | |||
− | |||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Here are some self assessment questions for you to solve. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| Here are some self assessment questions for you to solve. | ||
− | # Draw a '''plot''' of '''cosine graph''' between ''' | + | # Draw a '''plot''' of '''cosine graph''' between '''minus''' '''2pi to 2pi''' with line thickness 4. |
# Read the documentation and find out, is there a way to modify the '''alignment''' of text in the '''command ylabel'''. | # Read the documentation and find out, is there a way to modify the '''alignment''' of text in the '''command ylabel'''. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
Line 483: | Line 464: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| And the answers, | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0in;padding-bottom:0in;padding-left:0.0382in;padding-right:0.075in;"| And the answers, | ||
− | 1. In order to '''plot''' a '''cosine graph''' between the points | + | 1. In order to '''plot''' a '''cosine graph''' between the points '''minus '''2pi and 2pi with line thickness 4,we use the '''linspace''' and''' plot''' '''command '''as, |
− | '''x | + | '''x equals to linspace inside the brackets minus 2pi comma 2pi.''' |
− | '''plot | + | '''plot (x comma cos(x) comma linewidth equals to 4)''' |
+ | |||
+ | The answer to the second question is: | ||
2. No. We do not have an option to modify the '''alignment '''of text in the '''command''' '''ylabel'''. | 2. No. We do not have an option to modify the '''alignment '''of text in the '''command''' '''ylabel'''. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- |
Latest revision as of 13:25, 28 February 2017
Python/C2/Embellishing a Plot/English
Title of script: Embellishing a Plot
Author: Pravin, Aditya Palaparthy
Keywords: Python, IPython, plot, title
|
|
Title Slide | Hello Friends. Welcome to the tutorial on "Embellishing a Plot". |
Show Slide
Objectives |
At the end of this tutorial, we will learn to-
|
Show Slide
System Requirements |
To record this tutorial, I am using
|
Show slide
Pre-requisites |
To practice this tutorial, you should know how to
If not, see the pre-requisite Python tutorials on this website. |
[Terminal]
ipython3 and press Enter. |
Let us start ipython3.
Open the terminal. Type ipython3 and press Enter. |
[IPython console]
%pylab and press Enter. |
Let us initialise the pylab package
Type percentage pylab and press Enter. |
[IPython console]
x = linspace(-2, 4, 20) and press Enter. |
We shall first make a simple plot and start modifying it.
|
plot(x, sin(x)) and press Enter. | Then type plot inside the brackets x comma sin(x) and press Enter. |
[Plot Window] | We can now see the sine curve in the plot window.
|
Let us now change the parameters of this curve.
| |
[IPython console]
clf() and press Enter. |
We shall first clear the plot window by typing clf() in the ipython console. |
[Plot window] | You can now see a blank plot window. |
[IPython console]
plot(x, sin(x), 'r') and press Enter. |
Now plot the same sine curve with an additional color argument.
Here, the argument 'r' is for red color. |
Show the sine curve on the plot window by moving the mouse pointer on it.
|
On the plot window, the same sine curve is now seen in red color.
|
[Ipython console] | We can alter the thickness of the line by using the 'linewidth' argument. |
[IPython console]
|
This time we will draw the cosine curve on the plot window.
|
[Plot window]
compare the sine and cosine plots |
A cosine curve with line thickness 2 is produced in the plot window. |
Let us now try to plot a sine curve in blue color with linewidth as 3. | |
[IPython console] | Here onwards,
|
[IPython console]
clf() |
First let us clear the plot window by typing clf().
You will again see a blank plot window. |
[IPython console]
plot(x, sin(x), 'b', linewidth=3) |
Now type plot inside the brackets x comma sin(x) comma inside inverted commas b comma linewidth equals to 3
|
[Ipython console] | To get the plot in dotted style instead of a solid style, put a dot in linestyle. |
[IPython console]
clf() |
First, type clf() to clear the plot window. |
[IPython console]
plot(x, sin(x), '.')
|
Now type plot inside the brackets x comma sin(x) comma inside inverted commas dot. |
[Plot Window] | We get the sine curve in dotted style. |
[IPython console]
plot? Run through the information and show the options available Show the options available for line style and colors |
Let's see the information of plot.
|
Show Slide
Exercise 1
|
Pause the video. Try this exercise and then resume the video
|
Let us switch to the console for the solution. | |
[IPython console]
clf() |
Type clf() to clear the plot window. |
[IPython console]
plot(x, cos(x), 'r--',linewidth=3)
|
Now type plot inisde brackets x comma cos(x) comma inside inverted commas r hypen hypen comma linewidth equals to 3
|
Now we know how to produce a bare minimum plot with color, style and thickness.
| |
[IPython console]
plot(x, -x*x + 4*x - 5, 'r', linewidth=2) |
Let us start with a plot for the function minus x square plus 4x minus 5.
|
[Plot window] | We will see the curve of this equation in the plot window.
|
[IPython console]
title("Parabolic function -x^2+4x-5") |
To add a title to the plot, use the title command.
|
[IPython console]
Highlight the title command |
The title command as you can see, takes a string as an argument. |
Show the plot window and point to the title | We can see the title on the plot window.
|
Show the plot window and point to the title | It would look even more shabby if there were fractions and complex functions.
|
[IPython console]
title(r"Parabolic function $-x^2+4x-5$") |
For LaTeX format, we put a dollar sign before and after the string.
It will ignore all escape codes. |
[Plot Window]
Point at the polynomial |
As we can see that the polynomial in the title is now formatted. |
[IPython console]
xlabel(r"$x$") ylabel(r"$y$") |
Although we have title, the plot is not complete without labelling the x and y axes.
So we will label x and y axes in LaTeX style.
|
[IPython console]
|
The plot is now almost complete.
|
[Plot Window]
|
We can see the local maxima at point (2 comma minus 1) |
[IPython console]
|
The first argument in annotate command is the name of the point.
|
[IPython console]
xlim() ylim() |
Next, type xlim brackets
xlim function returns the current x axis limits.
ylim function returns the current y-axis limits. |
[IPython console]
ylim(-15, 2) |
Set the limits of x-axis from minus 4 to 5 by typing xlim inside the brackets minus 4 comma 5
|
Show Slide
Exercise 2
|
Pause the video. Try this exercise and then resume the video.
What happens to the first annotation? |
[IPython console]
|
Switch to the Ipython console for the solution.
|
Show Slide
Summary slide
|
This brings us to the end of this tutorial. In this tutorial, we have learnt to,
|
Show Slide
Evaluation |
Here are some self assessment questions for you to solve.
|
Show Slide
Solutions
|
And the answers,
1. In order to plot a cosine graph between the points minus 2pi and 2pi with line thickness 4,we use the linspace and plot command as, x equals to linspace inside the brackets minus 2pi comma 2pi. plot (x comma cos(x) comma linewidth equals to 4) The answer to the second question is: 2. No. We do not have an option to modify the alignment of text in the command ylabel. |
Show Slide
Forum to answer questions |
Do you have questions on THIS Spoken Tutorial?
Choose the minute and second where you have the question. Explain your question briefly. Someone from the FOSSEE team will answer them. Please visit this site. |
Show Slide
Forum to answer questions |
Do you have any general / technical questions on Python?
|
Show Slide
Textbook Companion |
The FOSSEE team coordinates coding of solved examples of popular books.
We give honorarium and certificates for those who do this. For more details, please visit this site. |
Show Slide
Acknowledgement |
The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India |
Show Slide
Thank You |
This is (________) from IIT Bombay signing off. Thanks for watching |