Slartibartfast
Slartibartfast

Reputation: 1190

Plotting n number of plots side by side

I have the following script:

import fxcmpy
import pandas as pd
from pandas import datetime
from pandas import DataFrame as df
import matplotlib
from pandas_datareader import data as web
import matplotlib.pyplot as plt
import datetime
from datetime import date
import numpy as np
TOKEN = "d0d2a3295349c625be6c0cbe23f9136221eb45ef"
con = fxcmpy.fxcmpy(access_token=TOKEN, log_level='error')
print(con.get_instruments())
ticker= con.get_instruments()
start = datetime.datetime(2008,1,1)
end = datetime.datetime.today()
today = date.today()
data = con.get_candles(ticker, period='D1', start = start, end = end)
data.index = pd.to_datetime(data.index, format ='%Y-%m-%d')

the variable symbol contains the following list:

['EUR/USD', 'USD/JPY', 'GBP/USD', 'USD/CHF', 'EUR/CHF', 'AUD/USD', 'USD/CAD', 'NZD/USD', 'EUR/GBP', 'EUR/JPY', 'GBP/JPY', 'CHF/JPY', 'GBP/CHF', 'EUR/AUD', 'EUR/CAD', 'AUD/CAD', 'AUD/JPY', 'CAD/JPY', 'NZD/JPY', 'GBP/CAD', 'GBP/NZD', 'GBP/AUD', 'AUD/NZD', 'USD/SEK', 'EUR/SEK', 'EUR/NOK', 'USD/NOK', 'USD/MXN', 'AUD/CHF', 'EUR/NZD', 'USD/ZAR', 'USD/HKD', 'ZAR/JPY', 'USD/TRY', 'EUR/TRY', 'NZD/CHF', 'CAD/CHF', 'NZD/CAD', 'TRY/JPY', 'USD/CNH', 'AUS200', 'ESP35', 'FRA40', 'GER30', 'HKG33', 'JPN225', 'NAS100', 'SPX500', 'UK100', 'US30', 'Copper', 'CHN50', 'EUSTX50', 'USDOLLAR', 'US2000', 'USOil', 'UKOil', 'SOYF', 'NGAS', 'WHEATF', 'CORNF', 'Bund', 'XAU/USD', 'XAG/USD', 'EMBasket', 'JPYBasket', 'BTC/USD', 'BCH/USD', 'ETH/USD', 'LTC/USD', 'XRP/USD', 'CryptoMajor', 'ESPORTS', 'BIOTECH', 'CANNABIS', 'FAANG', 'CHN.TECH', 'CHN.ECOMM', 'USEquities']

How can I plot them all side by side?

I can plot one at a time with data.plot(y='bidopen') but I am wondering how I can plot them all at the same time side by side.

Upvotes: 1

Views: 221

Answers (1)

MkWTF
MkWTF

Reputation: 1372

You can use matplotlib's subplots function to do this. Here is an example with a synthetic dataset:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({
    "group": [ i for i in range(3) for j in range(10) ],
    "x":     [ j for i in range(3) for j in range(10) ],
    "y":     [ pow(j+1, i+1) for i in range(3) for j in range(10) ]
})

fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(12, 4))
for i in range(3):
    df[ df.group == i ].plot("x", "y", ax=axes[i])

plt.show()

And here is the result:

enter image description here

Upvotes: 2

Related Questions