Chapter 4 - Practical Data Visualization
Segment 2 - Defining elements of a plot
import numpy as np
from numpy.random import randn
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
from matplotlib import rcParams
%matplotlib inline
rcParams['figure.figsize']=5,4
Defining axes, ticks, and grids
x = range(1,10)
y = [1,2,3,4,0,4,3,2,1]
fig = plt.figure()
ax = fig.add_axes([.1,.1,1,1])
ax.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716e09d240>]
fig = plt.figure()
ax = fig.add_axes([.1,.1,1,1])
ax.set_xlim([1,9])
ax.set_ylim([0,5])
ax.set_xticks([0,1,2,4,5,6,8,9,10])
ax.set_yticks([0,1,2,3,4,5])
ax.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716d98a8d0>]
fig = plt.figure()
ax = fig.add_axes([.1,.1,1,1])
ax.set_xlim([1,9])
ax.set_ylim([0,5])
ax.grid()
ax.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716d9a3be0>]
fig = plt.figure()
fig,(ax1, ax2) = plt.subplots(1,2)
ax1.plot(x)
ax2.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f716d873f98>]
<Figure size 360x288 with 0 Axes>