Book Image

Mastering Python for Data Science

By : Samir Madhavan
Book Image

Mastering Python for Data Science

By: Samir Madhavan

Overview of this book

Table of Contents (19 chapters)
Mastering Python for Data Science
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Estimating the Likelihood of Events
Index

Controlling the line properties of a chart


There are many properties of a line that can be set, such as the color, dashes, and several others. There are essentially three ways of doing this. Let's take a simple line chart as an example:

>>> plt.plot([1,2,3,4], [1,4,9,16])
>>> plt.show()

After the preceding code is executed we'll get the following output:

Using keyword arguments

We can use arguments within the plot function to set the property of the line:

>>> import numpy as np
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> import pandas.tools.rplot as rplot

>>> plt.plot([1, 2, 3, 4], [1, 4, 9, 16], linewidth=4.0)  # increasing # the line width
>>> plt.show()

After the preceding code is executed we'll get the following output:

Using the setter methods

The plot function returns the list of line objects, for example line1, line2 = plot(x1,y1,x2,y2). Using the line setter method of line objects we can define...