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()

```
Looking more in the direction of the attempt in the question, the only problem in the code is that `ax = fig.add_subplot()` returns `None` **because it has no argument given**. 

The usual way is to call `ax = fig.add_subplot(111)` or any other (set of) argument(s) that actually creates a subplot. [See documentation](http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.add_subplot).

Therefore the code from the question works fine, if that argument is given.

```
import matplotlib.pyplot as plt
import pandas as pd
r = pd.DataFrame({"TOTAL DATA" : [1000,2000,3000]})

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

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

```