I am trying to plot a df that must have two y-axes. I can get the plot to work using only one axis, but when I use two it comes out empty. I\'ve tried separating into two se
It looks like you're explicitly plotting them both on the same axes. You've made a new figure and a second axes called ax2
, but you're plotting the second dataframe on the first axes by calling df2.plot(..., ax=ax)
instead of df2.plot(..., ax=ax2)
As a simplified example, you're basically doing:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Generate some placeholder data
df1 = pd.DataFrame(np.random.random(10))
df2 = pd.DataFrame(np.random.random(10))
fig, ax = plt.subplots()
df1.plot(ax=ax)
fig, ax2 = plt.subplots()
df2.plot(ax=ax)
plt.show()
When you want something more like:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Generate some placeholder data
df1 = pd.DataFrame(np.random.random(10))
df2 = pd.DataFrame(np.random.random(10))
fig, ax = plt.subplots()
df1.plot(ax=ax)
fig, ax2 = plt.subplots()
df2.plot(ax=ax2) # Note that I'm specifying the new axes object
plt.show()