Slartibartfast
Slartibartfast

Reputation: 1190

For loop for plotting multiple plots in matplotlib

for symbol in symbols:
    data = con.get_candles(symbol, period='D1', start = start, end = end)
    data1 = con.get_candles('USOil', period='D1', start = start1, end = end)
    ax = data['bidclose'].plot()
    data1['bidclose'].plot(ax=ax)

I have used the code above in the hope that it will plot symbol and usoil in 1 chart and then produce another chart with the next in line symbol and usoil until all the symbol list has been exhaused. However evertything is getting plotted in the same chart.

enter image description here

How can i use the for-loop where 1 symbol in the list of symbols and usoil get plotted? Thus there will be n numbers of plots where n is the number of symbol in symbols.

Upvotes: 0

Views: 331

Answers (1)

Solvalou
Solvalou

Reputation: 1143

Just put plt.show() in your routine:

for symbol in symbols:
    data = con.get_candles(symbol, period='D1', start = start, end = end)
    data1 = con.get_candles('USOil', period='D1', start = start1, end = end)
    ax = data['bidclose'].plot()
    data1['bidclose'].plot(ax=ax)
    plt.show()

Upvotes: 1

Related Questions