How can I make a bar plan and a linear plan on the same sea section with different Y-axes?

I have two different datasets with a common index, and I want to present the first as a barplot, and the second as a line chart on the same chart. My current approach is similar to the following.

ax = pt.a.plot(alpha = .75, kind = 'bar')
ax2 = ax.twinx()
ax2.plot(ax.get_xticks(), pt.b.values, alpha = .75, color = 'r')

And the result is similar to this

Row and row with the same data

This image is really nice and almost correct. My only problem is that ax.twinx()it seems to be creating a new canvas on top of the previous one, and the white lines are clearly visible on top of the barrel.

Is there any way to build this without including white lines?

+4
source share
1 answer

. ax2.grid(False). y- y- y, :

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(pd.Series(np.random.uniform(0,1,size=10)), color='g')
ax2 = ax1.twinx()
ax2.plot(pd.Series(np.random.uniform(0,17,size=10)), color='r')
ax2.grid(False)
plt.show()

enter image description here

0

All Articles