Feeds:
Posts

## Python: plotting examples

```In this post, I discuss one easy plot in Python (using Matplotlib).

To plot the function y=exp(x) in the range [0., 1.], one can do the following:

>>> from pylab import *
>>> a = arange(0,1,.02)
>>> b = exp(a)
>>> plot(a,b,'r-')   # 'r' means with red color and '-' means with dashed line style

```

### It is ready at this point, but we would like to add error bars:

```>>> e = 0.2*abs(randn(len(b)))       # prepare errorbar from random numbers
>>> errorbar(a, b, e, fmt='o', label='y=exp(x)')             # vertical symmetric

Now, we plan to add a legend and axes labels:
>>> legend()                 # the label command in errorbar contains the legend

>>> xlabel('x')
>>> xlabel('y')
>>> show()
The following plot will appear on your screen:
Simple plot with error bar and legend
You can save image in a few formats like PNG, EPS, etc using a save button in the image box.
In a following post, I will show how to create a map and overlay contour of another map on it.

__ATA.cmd.push(function() {
__ATA.initVideoSlot('atatags-370373-5b27e7ef9ccda', {
sectionId: '370373',
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-26942-5b27e7ef9cd05',  {
collapseEmpty: 'before',
sectionId: '26942',
width: 300,
height: 250
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-114160-5b27e7ef9cd07',  {
collapseEmpty: 'before',
sectionId: '114160',
width: 300,
height: 250
});
});