--- a/advanced-features-functions/questions.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/advanced-features-functions/questions.rst Mon Oct 11 22:44:55 2010 +0530
@@ -17,6 +17,9 @@
#. only keyword arguments can be in any order, but should be called
at the end.
+ Answer: only keyword arguments can be in any order, but should be called
+ at the end.
+
#. Given the following function, identify the keywords with default
values.
::
@@ -101,8 +104,6 @@
Larger Questions
----------------
-.. A minimum of 2 questions here (along with answers)
-
1.
2.
--- a/getting-started-files/questions.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/getting-started-files/questions.rst Mon Oct 11 22:44:55 2010 +0530
@@ -37,7 +37,7 @@
What is the value of content, at the end of this code block::
f = open('hello.txt')
- content = f.read()
+ pre_content = f.read()
content = f.read()
f.close()
@@ -126,7 +126,7 @@
.. A minimum of 2 questions here.
-1. f.read(size)
+1. What does ``f.read(size)`` do?
#. Print every alternate line of a file, starting at the first line.
--- a/loading-data-from-files/questions.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/loading-data-from-files/questions.rst Mon Oct 11 22:44:55 2010 +0530
@@ -56,8 +56,12 @@
1. What will happen if one of the cells is empty?
-#. Read a column with text?
-
#. Given a file with 3 columns of data but two different delimiters,
what do you think will happen?
+#. Read a column with text?
+
+#. An input file contains 5 columns of data. Use only the second and fourth
+ columns of data and load into two different variables.
+ [hint: read the documentation, use the argument ``usecols``]
+
--- a/loops/questions.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/loops/questions.rst Mon Oct 11 22:44:55 2010 +0530
@@ -71,12 +71,6 @@
Answer::
- 1
- 2
- 3
- 2
- 4
- 6
3
6
9
@@ -94,5 +88,6 @@
Larger Questions
----------------
-.. A minimum of 2 questions here.
+1. A number is called Armstrong number if the sum of cubes of its digits is
+ equal to the number itself. Find all the three digit Armstrong numbers.
--- a/manipulating-strings/questions.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/manipulating-strings/questions.rst Mon Oct 11 22:44:55 2010 +0530
@@ -47,11 +47,11 @@
#. Given a line from a CSV file (comma separated values), convert it
to a space separated line.
- Answer: line.replace(',' ' ')
+ Answer: line.replace(',', ' ')
-#. Given the string "F.R.I.E.N.D.S" in s, obtain the friends.
+#. Given the string "F.R.I.E.N.D.S" in s, obtain the "friends".
- Answer: ``s[::2].lower()
+ Answer: ``s[::2].lower()``
Larger Questions
----------------
Binary file other-type-of-plots/bar-chart-hatch.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/other-type-of-plots/company-a-data.txt Mon Oct 11 22:44:55 2010 +0530
@@ -0,0 +1,2 @@
+2.000000000000000000e+03 2.001000000000000000e+03 2.002000000000000000e+03 2.003000000000000000e+03 2.004000000000000000e+03 2.005000000000000000e+03 2.006000000000000000e+03 2.007000000000000000e+03 2.008000000000000000e+03 2.009000000000000000e+03 2.010000000000000000e+03
+2.300000000000000000e+01 5.500000000000000000e+01 3.200000000000000000e+01 6.500000000000000000e+01 8.800000000000000000e+01 5.000000000000000000e+00 1.400000000000000000e+01 6.700000000000000000e+01 2.300000000000000000e+01 2.300000000000000000e+01 1.200000000000000000e+01
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/other-type-of-plots/questions.rst Mon Oct 11 22:44:55 2010 +0530
@@ -0,0 +1,85 @@
+Objective Questions
+-------------------
+
+.. A mininum of 8 questions here (along with answers)
+
+1. What is a log-log chart?
+
+ a. A straight line graph
+ #. A graph on the logarithmic scale
+ #. A graph on the logarithmic scale with different scales for x and
+ y axes
+ #. A graph in which x axis is represented in logarithmic scale.
+
+Answer: A graph on the logarithmic scale with different scales for x
+ and y axes
+
+2. We have two lists with us ``years`` and ``profit``, what statement
+ can be issued to plot a pie chart to plot the profit for each year,
+ and each wedge has to be labelled with the corresponding year.
+
+Answer: pie(profit, labels=years)
+
+3. We have two lists with us ``years`` and profit``, what statement
+ can be issued to plot a scatter plot of the data in blue colored
+ diamonds. ``years`` has to be plotted along x-axis.
+
+Answer: scatter(year,profit,color='blue',marker='d')
+
+4. ``scatter(x, y, color='blue', marker='d')`` and ``plot(x, y,
+ color='b', marker='d')`` does exactly the same.
+
+ a. True
+ #. False
+
+Answer: False
+
+5. ``plot(x, y, 'bd')`` creates a scattered plot in blue color and
+ diamond markers?
+
+ a. True
+ #. False
+
+Answer: True
+
+6. ``scatter(x, y, 'bd')`` creates a scatter plot in blue color with
+ diamond markers.
+
+ a. True
+ #. False
+
+Answer: False
+
+7. What statement can be issued to generate a bar chart with 135\
+ :sup:`o` hatched bar filled with white.
+
+ a. bar(x, y, color='w', hatch='/')
+ #. bar(x, y, color='w', hatch='\\')
+ #. bar(x, y, color='w', hatch='\')
+ #. bar(x, y, color='w', hatch='|')
+
+Answer: bar(x, y, color='w', hatch='\\')
+
+8. What statement can be issued to generate a bar chart with vertical
+ line hatching.
+
+ a. bar(x, y, color='w', hatch='/')
+ #. bar(x, y, fill=False, hatch='\\')
+ #. bar(x, y, fill=False, hatch='|')
+ #. bar(x, y, color='w', hatch='\')
+
+Answer: bar(x, y, fill=False, hatch='|')
+
+Larger Questions
+----------------
+
+.. A minimum of 2 questions here (along with answers)
+
+1. Plot a log-log chart of the equation y=4*x\ :sup:`2` + 3*x for x
+ from -50 to 50.
+
+2. Plot a bar chart which is filled with white color and which is
+ hatched with 135\ :sup:`o` slanting lines for the data given in the
+ `file(company A data) <company-a-data.txt>`_ which has years and
+ profit percentage for each year.
+
--- a/other-type-of-plots/script.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/other-type-of-plots/script.rst Mon Oct 11 22:44:55 2010 +0530
@@ -20,7 +20,6 @@
log plot. We will also see few other plots and also introduce you to
the matplotlib help.
-
Let us start with scatter plot.
{{{ switch to the next slide }}}
@@ -55,11 +54,12 @@
{{{ close the file and switch to the terminal }}}
-To product the scatter plot first we need to load the data from the
+To produce the scatter plot first we need to load the data from the
file using ``loadtxt``. We learned in one of the previous sessions,
and it can be done as ::
- year,profit = loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int()))
+ year,profit =
+ loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int()))
Now in-order to generate the scatter graph we will use the function
``scatter()``
@@ -100,9 +100,9 @@
pie(profit,labels=year)
-Notice that we passed two arguments to the function ``pie()``. The
-first one the values and the next one the set of labels to be used in
-the pie chart.
+Notice that we passed two arguments to the function ``pie()``. First
+one the values and the next one the set of labels to be used in the
+pie chart.
{{{ switch to the next slide which has the problem statement of
problem to be tried out }}}
@@ -195,14 +195,10 @@
Help about matplotlib can be obtained from
matplotlib.sourceforge.net/contents.html
-.. #[[Anoop: I am not so sure how to do the rest of it, so I guess we
- can just browse through the side and tell them few. What is your
- opinion??]]
-Now let us see few plots from
-matplotlib.sourceforge.net/users/screenshots.html
-
-{{{ browse through the site quickly }}}
+More plots can be seen at
+matplotlib.sourceforge.net/users/screenshots.html and also at
+matplotlib.sourceforge.net/gallery.html
{{{ switch to recap slide }}}
--- a/savefig/script.rst Mon Oct 11 13:42:52 2010 +0530
+++ b/savefig/script.rst Mon Oct 11 22:44:55 2010 +0530
@@ -9,8 +9,16 @@
Savefig
=======
-Hello and welcome to the tutorial. In this tutorial you will learn how
-to save plots using Python.
+{{{ Show the first slide }}}
+
+Hello and welcome to the tutorial saving plots.
+
+{{{ switch to next slide, outline slide }}}
+
+In this tutorial you will learn how to save plots using Python. And
+saving in different formats, and locating the file in the file system.
+
+{{{ switch to next slide, a sine wave}}}
Start your IPython interpreter with the command ::
@@ -38,9 +46,11 @@
the plot for future use so that you can embed the plot in your
reports.
+{{{ switch to next slide, savefig() }}}
+
{{{ Switch the focus to IPython interpreter window }}}
-For saving the plot, we will use savefig function, and it has to be
+For saving the plot, we will use ``savefig()`` function, and it has to be
done with the plot window open. The statement is, ::
savefig('/home/fossee/sine.png')
@@ -73,6 +83,8 @@
close it and return to IPython interpreter, make sure the plot window
is still open, also don't close the file browser window }}}
+{{{ switch to next slide, More on savefig() }}}
+
So in-order to save a plot, we use ``savefig`` function. ``savefig``
can save the plot in many formats, such as pdf - portable document
format, ps - post script, eps - encapsulated post script, svg -
@@ -81,15 +93,19 @@
.. #[[slide must give the extensions for the files - Anoop]]
+{{{ switch to next slide, exercise 1 }}}
+
Let us now try to save the plot in eps format. ``eps`` stands for
encapsulated post script, and it can be embedded in your latex
-documents.
+documents. Pause here and try to figure it out yourself.
{{{ Switch focus to the already open plot window }}}
We still have the sine plot with us, and now let us save the plot as
``sine.eps``.
+{{{ switch to next slide, solution 1 }}}
+
{{{ Switch focus to IPython interpreter }}}
Now, We will save the plot using the function ``savefig`` ::
@@ -105,10 +121,17 @@
Yes! the new file ``sine.eps`` is here.
+{{{ switch to next slide, exercise 2 }}}
+
Now you may try saving the same in pdf, ps, svg formats.
-Let us review what we have learned in this session! We have learned to
-save plots in different formats using the function ``savefig()``.
+{{{ Switch to summary slide }}}
+
+This brings us to the end of this tutorial, in this tutorial we
+learned to save plots using the function ``savefig()``. Saving the
+plots in different formats and locating the files in the file system.
+
+{{{ switch to Thank you slide }}}
Thank you!
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/savefig/slides.org Mon Oct 11 22:44:55 2010 +0530
@@ -0,0 +1,99 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
+#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
+
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+
+#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
+#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+
+#+LaTeX_HEADER: \usepackage{listings}
+
+#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+
+#+TITLE: Savefig
+#+AUTHOR: FOSSEE
+#+EMAIL: info@fossee.in
+#+DATE: 2010-10-11 Mon
+
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE: en
+#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
+#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
+
+* Outline
+ - Saving plots.
+ - Plotting in different formats.
+ - Locating the file in the file system.
+
+* Creating a basic plot
+ Plot a sine wave from -3pi to 3pi.
+ #+begin_src python
+ In []: x = linspace(-3*pi,3*pi,100)
+
+ In []: plot(x, sin(x))
+ #+end_src
+* savefig()
+** savefig() - to save plots
+ : syntax: savefig(fname)
+** example
+*** savefig('/home/fossee/sine.png')
+ - file sine.png saved to the folder /home/fossee
+ - .png - file type
+
+* More on savefig()
+** Recall
+ - .png - file type
+** File types supported
+*** .pdf - PDF(Portable Document Format)
+*** .ps - PS(Post Script)
+*** .eps - Encapsulated Post Script
+ ~to be used with~ LaTeX ~documents~
+*** .svg - Scalable Vector Graphics
+ ~vector graphics~
+*** .png - Portable Network Graphics
+ ~supports transparency~
+* Exercise 1
+ Save the sine plot in the format EPS which can be embedded in LaTeX documents.
+* Solution 1
+ #+begin_src python
+ savefig('/home/fossee/sine.eps')
+ #+end_src
+* Exercise 2
+ Save the sine plot in PDF, PS and SVG formats.
+
+* Summary
+ You should now be able to
+ - Use ~savefig()~ function
+ - Save plots in different formats
+ - PDF
+ - PS
+ - PNG
+ - SVG
+ - EPS
+ - Locating the files in file system.
+
+* Thank you!
+#+begin_latex
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+#+end_latex
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/savefig/slides.tex Mon Oct 11 22:44:55 2010 +0530
@@ -0,0 +1,185 @@
+% Created 2010-10-11 Mon 17:08
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{t1enc}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\usepackage{amssymb}
+\usepackage{hyperref}
+\tolerance=1000
+\usepackage[english]{babel} \usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
+\usepackage{listings}
+\lstset{language=Python, basicstyle=\ttfamily\bfseries,
+commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
+showstringspaces=false, keywordstyle=\color{blue}\bfseries}
+\providecommand{\alert}[1]{\textbf{#1}}
+
+\title{Savefig}
+\author{FOSSEE}
+\date{2010-10-11 Mon}
+
+\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+\begin{frame}
+\frametitle{Outline}
+\label{sec-1}
+
+\begin{itemize}
+\item Saving plots.
+\item Plotting in different formats.
+\item Locating the file in the file system.
+\end{itemize}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Creating a basic plot}
+\label{sec-2}
+
+ Plot a sine wave from -3pi to 3pi.
+\begin{verbatim}
+In []: x = linspace(-3*pi,3*pi,100)
+
+In []: plot(x, sin(x))
+\end{verbatim}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{savefig()}
+\label{sec-3}
+\begin{itemize}
+
+\item savefig() - to save plots
+\label{sec-3_1}%
+\begin{verbatim}
+ syntax: savefig(fname)
+\end{verbatim}
+
+
+\item example
+\label{sec-3_2}%
+\begin{itemize}
+
+\item savefig('/home/fossee/sine.png')
+\label{sec-3_2_1}%
+\begin{itemize}
+\item file sine.png saved to the folder /home/fossee
+\item .png - file type
+\end{itemize}
+
+
+\end{itemize} % ends low level
+\end{itemize} % ends low level
+\end{frame}
+\begin{frame}
+\frametitle{More on savefig()}
+\label{sec-4}
+\begin{itemize}
+
+\item Recall
+\label{sec-4_1}%
+\begin{itemize}
+\item .png - file type
+\end{itemize}
+
+
+\item File types supported
+\label{sec-4_2}%
+\begin{itemize}
+
+\item .pdf - PDF(Portable Document Format)\\
+\label{sec-4_2_1}%
+\item .ps - PS(Post Script)\\
+\label{sec-4_2_2}%
+\item .eps - Encapsulated Post Script\\
+\label{sec-4_2_3}%
+\texttt{to be used with} \LaTeX{} \texttt{documents}
+
+\item .svg - Scalable Vector Graphics\\
+\label{sec-4_2_4}%
+\texttt{vector graphics}
+
+\item .png - Portable Network Graphics\\
+\label{sec-4_2_5}%
+\texttt{supports transparency}
+\end{itemize} % ends low level
+\end{itemize} % ends low level
+\end{frame}
+\begin{frame}
+\frametitle{Exercise 1}
+\label{sec-5}
+
+ Save the sine plot in the format EPS which can be embedded in \LaTeX{} documents.
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-6}
+
+\begin{verbatim}
+savefig('/home/fossee/sine.eps')
+\end{verbatim}
+\end{frame}
+\begin{frame}
+\frametitle{Exercise 2}
+\label{sec-7}
+
+ Save the sine plot in PDF, PS and SVG formats.
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-8}
+
+ You should now be able to
+\begin{itemize}
+\item Use \texttt{savefig()} function
+\item Save plots in different formats
+
+\begin{itemize}
+\item PDF
+\item PS
+\item PNG
+\item SVG
+\item EPS
+\end{itemize}
+
+\item Locating the files in file system.
+\end{itemize}
+
+
+\end{frame}
+\begin{frame}
+\frametitle{Thank you!}
+\label{sec-9}
+
+ \begin{block}{}
+ \begin{center}
+ This spoken tutorial has been produced by the
+ \textcolor{blue}{FOSSEE} team, which is funded by the
+ \end{center}
+ \begin{center}
+ \textcolor{blue}{National Mission on Education through \\
+ Information \& Communication Technology \\
+ MHRD, Govt. of India}.
+ \end{center}
+ \end{block}
+\end{frame}
+
+\end{document}