Question: I think I'm missing something in the workflow of matplotlib... I'm trying to create a figure of custom size, add some stuff, then add a second axis:

```
#temp graph
import matplotlib.pyplot as plt
plt.cla()
plt.clf()
plt.close()
df = r

fig = plt.figure(figsize=(14,6))
ax = fig.add_subplot()

#r is a dataframe filled with a bunch of data

myplot = r[r.index<=100]["TOTAL DATA"].apply(lambda x:x/1000).plot(kind='bar')
ax2 = ax.twinx()
plt.show()

```

This gives me the following error:

> 
> AttributeError Traceback (most recent call
>  last) in ()
>  13 
>  14 
>  ---> 15 ax2 = ax.twinx()
>  16 
>  17 plt.show()
> 
> 
> AttributeError: 'NoneType' object has no attribute 'twinx'
> 
> 
> 

Any thoughts? Thanks!

Answer: 
The function `fig.add_subplot()` returns `nothing` (**None**), so you will not have a new Axes. You must use the `plt.subplots()` function, it returns a Figure object and an Axes object

```
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

plt.cla()
plt.clf()
plt.close()
r = pd.DataFrame(np.random.randn(6,1),columns=['TOTAL DATA'])

fig, ax= plt.subplots(figsize=(14, 6))

myplot = r[r.index<=100]["TOTAL DATA"].apply(lambda x:x/1000).plot(kind='bar')
ax2 = ax.twinx()
plt.show()

```
simple issue. the ax variable isn't the axes in scope. myplot is. myplot.twinx() works.