6.2. Import/Export

6.2.1. Reading data

  • with open('filename.csv') - context manager

  • numpy.loadtxt('filename.csv', delimeter=',', unpack=True)

  • csv.DictReader()

  • pandas DataFrame

6.2.2. pandas and matplotlib

  • All of plotting functions expect np.array or np.ma.masked_array as input

  • Classes that are 'array-like' such as pandas data objects and np.matrix may or may not work as intended

  • It is best to convert these to np.array objects prior to plotting

  • Convert a pandas.DataFrame:

    a = pandas.DataFrame(np.random.rand(4,5), columns = list('abcde'))
    a_asndarray = a.values
    

6.2.3. Exporting

eps
pdf
png
ps
svg
raster graphics
vector graphics

Renderer

Filetypes

Type

Description

AGG

png

raster graphics

High quality images using the Anti-Grain Geometry engine

PS

ps, eps

vector graphics

Postscript output

PDF

pdf

vector graphics

Portable Document Format

SVG

svg

vector graphics

Scalable Vector Graphics

Cairo

png, svg

raster graphics, vector graphics

using the Cairo graphics library