Lecture 25 Plotting II

In this lecture, we will learn:
1)
Error Bars
2) The Bar Chart

Before we move forward with more plotting functions, please go through the tutorials for Vim and Git at here. Try to type your code in Vim and upload it to Git every time from now and in the future.

This homework should be uploaded to GitHub. Send the link of the repository to the homework email so I can go there and check it out.

1. Error bars
Let's add some error bars to the line data figure first:
(Again, if you are using Vim as the text editor, you need plt.show() in the end of this script)


Oops! The legend is not showing the entire text...
However, if I put the legend text into a 'list' or a 'tuple', it works out well.



The reason is you are expected to pass in an iterable of strings, but you pass in just one string. A string is an iterable of strings too (it yields individual characters), which is why only the first character is used.

If you have more lines to be plotted in one figure, you can simply do it as follows:





You can change the line for the second line:



The line and the error bar is not that nice. Let's modify it:
('numpoints=1' in the legend function means show 1 marker in the legend area)



Wow! This looks much nicer, close to the publishable quality.
Need a better resolution for the figure? Try this:



The saved image will appear in the same directory as you .py file, I zoomed-in the image, the resolution is good enough for publications/presentations.



Also, you can plot it in a new window but not 'inline' in the IPython Console.



2. The Bar Chart
Let's plot a simplest bar chart first:



The X ticks can be changed to other texts easily by changing the X list.



Add error bars to them:



Grouped bar chart:



Try to remove the underlined contents in the figure above and you'll see why we have them there.



The orders of the parameters in 'plt.bar()' can be swapped.
The figure plotted is snipped separated:





Tasks:

(This homework should be uploaded to GitHub. Send the link of the repository to the homework email so I can go there and check it out.)

1. Data are presented in an excel file here. There are two workbooks in this excel file, one is 'task1' the other one is task2'.
Imagine you are asked to present these data in a poster (at lest 600 dpi for each figure). Use both the line chart and the bar chart to plot these data properly. The font of labels, legends, axis ticks, etc, embedded in the figure must be readable. The line width must be adjusted to a proper thickness.

The example script to load excel data to python:





The output is: