简体   繁体   中英

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.

在此处输入图片说明

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM