/ Python And R Data science skills: 78 plot range

Sunday, 18 February 2018

78 plot range

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 78 plot range
In [1]:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 5, 11)
y = x ** 2 
%matplotlib inline
In [15]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,color="#808000" ,lw=3,ls="steps")
Out[15]:
[<matplotlib.lines.Line2D at 0xa340e80>]
In [17]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,color="#808000" ,lw=3,ls="steps")
ax.set_xlim([0,2])
Out[17]:
(0, 2)
In [20]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,color="#808000" ,lw=3,ls="steps")
ax.set_xlim([0,1])
ax.set_ylim([0,2])
Out[20]:
(0, 2)
In [11]:
# MATLAB style line color and style 
fig, ax = plt.subplots()
ax.plot(x, x**2, 'b.-') # blue line with dots
ax.plot(x, x**3, 'g--') # green dashed line
Out[11]:
[<matplotlib.lines.Line2D at 0xa1bf4a8>]
In [12]:
fig, ax = plt.subplots()

ax.plot(x, x+1, color="blue", alpha=0.5) # half-transparant
ax.plot(x, x+2, color="#8B008B")        # RGB hex code
ax.plot(x, x+3, color="#FF8C00")        # RGB hex code 
Out[12]:
[<matplotlib.lines.Line2D at 0xa22c240>]
In [22]:
fig, axes = plt.subplots(1, 3, figsize=(12, 4))

axes[0].plot(x, x**2, x, x**3)
axes[0].set_title("default axes ranges")

axes[1].plot(x, x**2, x, x**3)
axes[1].axis('tight')
axes[1].set_title("tight axes")

axes[2].plot(x, x**2, x, x**3)
axes[2].set_ylim([0, 60])
axes[2].set_xlim([0, 20])
axes[2].set_title("custom axes range");

No comments:

Post a Comment