Reputation: 1
I have a bar Chart plotted with Pandas and want to insert multiple y-axises. Plotting the Chart, that is generated from the code below (see Picture link), it could be seen, that the first two blocks are too small for the scaling. How can I insert multiple y-axises, that every block is displayed well ? Using axis.twinx() only the column values are assigned to single y-axis but not the whole blocks, like I want.
from matplotlib import pyplot as plt
import pandas as pd
g = ['A1', 'B2', 'C3']
params = ['one', 'two', 'three']
data = [[1, 3e-5, 400], [2, 5e-5, 300], [1.5, 4e-5, 350]]
data_dict = dict(zip(g,data))
df=pd.DataFrame(data=data_dict,index=params,columns=g)
fig0, ax0 = plt.subplots()
ax1 = ax0.twinx()
df.plot(kind='bar', ax=ax0)
fig0.show()
Upvotes: 0
Views: 596
Reputation: 339705
Since the scales for the three params are so completely different, it probably makes sense to use three different subplots.
from matplotlib import pyplot as plt
import pandas as pd
g = ['A1', 'B2', 'C3']
params = ['one', 'two', 'three']
data = [[1, 3e-5, 400], [2, 5e-5, 300], [1.5, 4e-5, 350]]
data_dict = dict(zip(g,data))
df=pd.DataFrame(data=data_dict,index=params,columns=g)
fig0, ax = plt.subplots(ncols=3, figsize=(10,4))
for i, p in enumerate(params):
df.loc[[p,p], :].plot(kind='bar', ax=ax[i], )
ax[i].set_xlim([-.5,.5])
plt.tight_layout()
plt.show()
Upvotes: 1