Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding how to use matplotlib


The best way to understand the usage of the matplotlib module is through examples. The following example could be the simplest one since it has just three lines of Python code. The objective is to link several points. By default, the matplotlib module assumes that the x axis starts at zero and moves by one on every element of the array. The following command lines illustrate this situation:

>>>from matplotlib.pyplot import *
>>>plot([1,2,3,10])
>>>show()

After we press the Enter key after typing the last command of show(), the following graph will appear:

At the bottom of the graph, we can find a set of icons, and based on them, we could adjust our image and other functions, such as saving our image. After closing the preceding figure, we could return to Python prompt. On the other hand, if we issue show() the second time, nothing will happen. To repeat the preceding graph, we have to issue both plot([1,2,3,10]) and show().

We...