0

I am trying to create 3 horizontal bar charts in 3 separate subplots in matplotlib. However for some reason, all the graphs are being pasted onto only on one subplot rather than one in each of their own area.

cols = ["Education_Level", "Marital_Status", "Income_Category"]
fig, axs = plt.subplots(1, len(cols), figsize=(15, 6), tight_layout=True)

for idx, col_name in enumerate(cols):
    data = df[col_name].value_counts()
    axs[idx] = plt.barh(
        data.index,
        data.values
    )

Here is the result of my code

I have tried to manually separate it out. For example using axs(1) in order to forcefully have the graph showing in the middle subplot still doesn't work and still applies it to the last one.

hasan123
  • 5
  • 2
  • 5
    `axs[idx].barh(...)` – Quang Hoang May 10 '21 at 18:51
  • You should provide a fake minimal example of the DataFrame with your [mre]. [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – wwii May 10 '21 at 18:52
  • 1
    To illustrate @QuangHoang comment: Notice [in this example](https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html#stacking-subplots-in-two-directions) that the plot method is being called on the individual Axes - `barh` would be the same. – wwii May 10 '21 at 19:02

0 Answers0