You are previewing Beginning Python Visualization, Second Edition.
O'Reilly logo
Beginning Python Visualization, Second Edition

Book Description

We are visual animals. But before we can see the world in its true splendor, our brains, just like our computers, have to sort and organize raw data, and then transform that data to produce new images of the world. Beginning Python Visualization: Crafting Visual Transformation Scripts, Second Edition discusses turning many types of data sources, big and small, into useful visual data. And, you will learn Python as part of the bargain.

In this second edition youll learn about Spyder, which is a Python IDE with MATLAB -like features. Here and throughout the book, youll get detailed exposure to the growing IPython project for interactive visualization. In addition, you'll learn about the changes in NumPy and Scipy that have occurred since the first edition. Along the way, you'll get many pointers and a few visual examples.

As part of this update, youll learn about matplotlib in detail; this includes creating 3D graphs and using the basemap package that allows you to render geographical maps. Finally, you'll learn about image processing, annotating, and filtering, as well as how to make movies using Python. This includes learning how to edit/open video files and how to create your own movie, all with Python scripts.

Today's big data and computational scientists, financial analysts/engineers and web developers like you - will find this updated book very relevant.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Navigating the World of Data Visualization
    1. Gathering Data
      1. Case Study: GPS Data
      2. Scanning Serial Ports
      3. Recording GPS Data
    2. Data Organization
      1. File Format
      2. File Naming Conventions
      3. Data Location
    3. Data Analysis
      1. Walking Directories
      2. Reading CSV Files
      3. Analyzing GPS Data
      4. Extracting GPS Data
    4. Data Visualization
      1. GPS Location Plot
      2. Annotating the Graph
      3. Velocity Plot
      4. Subplots
      5. Text
    5. Tying It All Together
    6. Final Notes and References
  12. Chapter 2: The Environment
    1. Tools of the Trade
    2. Operating Systems
      1. GNU/Linux
      2. Windows
      3. Choosing an Operating System
      4. Then Again, Why Choose? Using Several Operating Systems
    3. The Python Environment
      1. Versions
      2. Python
      3. Python Integrated Development Environments
      4. Scientific Computing
      5. Manually Installing a Python Package
      6. Installation Summary
    4. Additional Applications
      1. Editors
      2. A Short List of Text Editors
      3. Spreadsheets
      4. Word Processors
      5. Image Viewers
      6. Version-Control Systems
    5. Licensing
    6. Final Notes and References
  13. Chapter 3: Python for Programmers
    1. The Building Blocks
    2. What Is Python?
    3. Interactive Python
      1. Invoking Python
      2. Entering Commands
      3. The Interactive Help System
      4. Moving Around
    4. Running Scripts
    5. Data Types
      1. Numbers
      2. Strings
      3. Booleans
    6. Data Structures
      1. Lists
      2. Tuples
      3. Dictionaries
      4. Sets
    7. Variables
    8. Statements
      1. Printing
      2. User Input
      3. Comments
      4. Flow Control
    9. Some Built-in Functions
    10. Defining Functions
      1. Generators
      2. Generator Expressions
    11. Object-Oriented Programming
    12. Modules and Packages
      1. The import Statement
      2. Modules Installed in a System
      3. The dir Statement
    13. Final Notes and References
  14. Chapter 4: Data Organization
    1. Organizing Chaos
    2. File Name Conventions
      1. Date and Time in a File Name
      2. Useful File Name Titles
      3. File Name Extensions
      4. File Name Convention Recap
      5. Other Schemes
    3. File Formats
      1. CSV File Format
      2. Binary Files
      3. Readme Files
      4. INI Files
      5. XML and Other Formats
    4. Locating Data Files
      1. Organization into Directories
      2. Searching for Files
      3. Indexing
      4. Catalogs
      5. Files vs. a Database
    5. Final Notes and References
  15. Chapter 5: Processing Text Files
    1. Text Is Everywhere
    2. Text and Strings
      1. Splitting Text
      2. Joining Strings
      3. Converting Strings to Numbers
      4. Find and Replace
      5. Stripping Strings
      6. String Formatting
      7. String Conditionals
      8. More on Strings
    3. Files
      1. Opening a File
      2. Closing a File
      3. Writing Text
      4. Reading Text
    4. Working with Text Files
      1. Example: Character, Word, and Line Count
      2. Example: head and tail
      3. Example: Splitting and Combining Files
      4. Example: Searching Inside a Text File
      5. Example: Working with Comments
      6. Example: Extracting Numbers from a Text File
    5. CSV Files
      1. The csv Module
      2. The csv.reader Object
      3. The csv.writer Object
      4. More CSV Functionality
      5. DictReader and DictWriter Objects
    6. Date and Time
      1. Time Module
      2. The struct_time Tuple
      3. Parsing and Formatting Date and Time
      4. The Epoch: “Linearizing” the Time Base
      5. Additional Time and Date Functions
    7. Regular Expressions
      1. Regular Expression Patterns
      2. Special Sequences
      3. Alternatives
      4. Ranges
      5. When to Use Regular Expressions
    8. Internationalization and Localization
      1. Locale
      2. Unicode Strings
    9. Final Notes and References
  16. Chapter 6: Graphs and Plots
    1. Visualizing Data
    2. The matplotlib Package
    3. Interactive Graphs vs. Image Files
      1. Interactive Graphs
      2. Savings Graphs to Files
    4. Plotting Graphs
      1. Lines and Markers
      2. Plotting Several Graphs on One Figure
      3. Line Widths and Marker Sizes
      4. Colors
    5. Controlling the Graph
      1. Axis
      2. Grid and Ticks
      3. Subplots
      4. Erasing the Graph
    6. Adding Text
      1. Title
      2. Axis Labels and Legend
      3. Text Rendering
      4. Mathematical Symbols and Expressions
    7. More Graph Types
      1. Bar Charts
      2. Histograms
      3. Pie Charts
      4. Logarithmic Plots
      5. Polar Plots
      6. Stem Plots
      7. Additional Graphs
    8. Getting and Setting Values
      1. Setting Figure and Axis Parameters
    9. Patches
      1. Example: Adding Arrows to a Graph
      2. Example: Some Other Patches
    10. 3D Plots
    11. The Basemap Toolkit
      1. Example: French Airports
    12. Final Notes and References
  17. Chapter 7: Math Games
    1. Preprocessing Data Prior to Visualization
    2. Modules math and cmath
      1. Example: Mandelbrot Set
      2. Example: A Newton Fractal
    3. Module decimal
    4. Module fractions
    5. Module random
      1. Using Module random to Solve Probability Questions
      2. Random Sequences
    6. Module NumPy
      1. Array Creation
      2. Slicing, Indexing, and Reshaping
      3. N-Dimensional Arrays
      4. Math Functions
      5. Array Methods and Properties
      6. Other Useful Array Functions
    7. Final Notes and References
  18. Chapter 8: Science and Visualization
    1. Numerical Analysis and Signal Processing
    2. Finding Your Way: Variables and Functions
      1. SciPy
    3. Linear Algebra
      1. Solving a System of Linear Equations
      2. Vector and Matrix Operations
      3. Matrix Decomposition
      4. Additional Linear Algebra Functionality
    4. Numerical Integration
      1. More Integration Methods
    5. Interpolation and Curve Fitting
      1. Piecewise Linear Interpolation
      2. Polynomials
      3. Uses of Polynomials
      4. Spline Interpolation
    6. Solving Nonlinear Equations
    7. Special Functions
    8. Signal Processing
      1. Functions find, nonzero, where and select
      2. Functions diff and split
      3. Waveforms
    9. Fourier Transform
      1. Example: FFT of a Sampled Cosine Wave
      2. Window Functions
    10. Filtering
      1. Filter Design
      2. Example: A Heart-Rate Monitor
      3. Example: Moving Average
    11. Final Notes and References
  19. Chapter 9: Image Processing
    1. Two-Dimensional Data
    2. Reading, Writing, and Displaying Images
      1. Reading Images from File
      2. Image Attributes
      3. Displaying Images
      4. Converting File Formats
    3. Image Manipulation
      1. Creating New Images
      2. Copy and Paste
      3. Crop and Resize
      4. Rotate
    4. Image Annotation
      1. Annotating with Geometrical Shapes
      2. Text Annotations
    5. Image Processing
      1. Matrix Representation and Colors
      2. Reading an Image to a NumPy Array
      3. Example: Counting Objects (Five Parts)
      4. Image Arithmetic
    6. Image Filtering
    7. Making Movies
      1. Splitting Movies
      2. Creating Movies from Images
      3. Example: A Fractal Movie
    8. Final Notes and References
  20. Chapter 10: Advanced File Processing
    1. More on Files
    2. Binary Files and Random Access
      1. Example: Reading the Nth Field
      2. Example: Efficient Tail Implementation
      3. Example: Creating a Fixed Size File
      4. Example: Recording Time-Based Binary Data
    3. Reading MATLAB Files as NumPy Arrays
    4. Reading Text Files Directly to NumPy Arrays
      1. Example: Reading and Writing Text Files to NumPy Arrays
    5. Object Serialization
      1. The Pickle Module
    6. Command-Line Parameters
      1. argv
      2. Example: Creating a Fixed Size File (a Stand-Alone Script)
      3. The optparse Module
      4. The FileInput Module
    7. File and Directory Manipulation
      1. Module glob
      2. Additional os Module Functionality
      3. Additional os.path Module Functionality
      4. Module shutil
    8. File Compression
      1. Example: A Compressed tar File
    9. Comparing Files
      1. Module filecmp
      2. Module difflib
    10. Final Notes and References
  21. Appendix: Additional Source Listing
    1. Nudge Subplots
    2. Magic Square Arrows
    3. Numerical Integration Visualization Source Code
    4. Fractal Function Source Code
  22. Index