0

people! I defined a function that makes a graph from matplotlib similar to this one taken from How to write a function for barchart in python?:

def df_bar(df, xcol, ycol, xlabel=None, ylabel=None, title=None):
    if xlabel is None:
        xlabel = xcol
    if ylabel is None:
        ylabel = xcol    
    ax = textranges_freq.plot(x=xcol,y=ycol,kind='bar',title=title, width=0.5, legend=False)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    plt.show()

My question is how to plot that into a matplotlib subplots funtion, what I mean is that, I want that graph appears two times side by side each, how do I make this?

I tried to define fig, axs and then using slicing "axs[0]" to plot, but didn't work, not even using subplots on matplotlib figure:

"ax1 = plt.subplot(1, 3, 1)
df_bar()
plt.title('bedrooms')"
3
  • matplotlib.org/stable/gallery/subplots_axes_and_figures/… Commented Jan 24, 2023 at 23:37
  • 1. fig, (ax1,ax2,ax3) = plt.subplots(1, 3) 2. add an ax=None param to your function 3. add the ax to your plot command like textranges_freq.plot(..., ax=ax) 4. call df_bar(..., ax=ax1) and so on Commented Jan 25, 2023 at 2:57
  • Note that this is plt.subplots ending in s Commented Jan 25, 2023 at 2:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.