/ Python And R Data science skills: 80 metabolite exercise

Sunday, 18 February 2018

80 metabolite exercise

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 80 metplotlib exercise
In [9]:
import numpy as np
x = np.arange(0,100)
y = x*2
z = x**2
Out[9]:
array([   0,    1,    4,    9,   16,   25,   36,   49,   64,   81,  100,
        121,  144,  169,  196,  225,  256,  289,  324,  361,  400,  441,
        484,  529,  576,  625,  676,  729,  784,  841,  900,  961, 1024,
       1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849,
       1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916,
       3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225,
       4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776,
       5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569,
       7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604,
       9801], dtype=int32)

Import matplotlib.pyplot as plt and set %matplotlib inline if you are using the jupyter notebook. What command do you use if you aren't using the jupyter notebook?

import matplotlib.pyplot as plt

%matplotlib inline

In [3]:
import matplotlib.pyplot as plt
%matplotlib inline

Exercise 1

Follow along with these steps:

  • Create a figure object called fig using plt.figure()
  • Use add_axes to add an axis to the figure canvas at [0,0,1,1]. Call this new axis ax.
  • Plot (x,y) on that axes and set the labels and titles to match the plot below:
In [10]:
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.plot(x,y)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('title')
Out[10]:
Text(0.5,1,'title')

Exercise 2

Create a figure object and put two axes on it, ax1 and ax2. Located at [0,0,1,1] and [0.2,0.5,.2,.2] respectively.

  • fig = plt.figure()

  • ax1 = fig.add_axes([0,0,1,1])

  • ax2 = fig.add_axes([0.2,0.5,.2,.2])
In [11]:
fig = plt.figure()

ax1 = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.2,0.5,.2,.2])

Now plot (x,y) on both axes. And call your figure object to show it.

  • ax1.plot(x,y)
  • ax1.set_xlabel('x')
  • ax1.set_ylabel('y')
  • ax2.plot(x,y)
  • ax2.set_xlabel('x')
  • ax2.set_ylabel('y')

  • fig # Show figure object

In [13]:
fig = plt.figure()

ax1 = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.2,0.5,.2,.2])
ax1.plot(x,y)
ax1.set_xlabel('x')
ax1.set_ylabel('y')


ax2.plot(x,y)
ax2.set_xlabel('x')
ax2.set_ylabel('y')

#fig # Show figure object
Out[13]:
Text(0,0.5,'y')

No comments:

Post a Comment