title: Speed up loop for matplotlib in python
body: <p>I have a similar, but larger data set with more dates and over ten thousand rows. Usually, it takes 3mins or longer to run the code and plot. I think the problem comes from loop. Looping is time-consuming in python. In this case, would be appreciated if someone knows how to rewrite the code to make it faster.</p>
  <pre><code>  data = {'Date' : [&quot;2022-07-01&quot;]*5000 + [&quot;2022-07-02&quot;]*5000+ [&quot;2022-07-03&quot;]*5000,        
            'OB1' : range(1,15001),
            'OB2' : range(1,15001)}
  
    df = pd.DataFrame(data)      
  
    # multi-indexing
    df = df.set_index(['Date'])
  
    # loop for plot
    i = 1
    fig, axs = plt.subplots(nrows = 1, ncols = 3, sharey = True)
    fig.subplots_adjust(wspace=0) 
    for j, sub_df in df.groupby(level=0):
        plt.subplot(130 + i)
        x = sub_df['OB1']
        y = sub_df['OB2']
        plt.barh(x, y) 
        i = i + 1
    plt.show() 
    
  </code></pre>