Как построить 3 или более значений в plot.bar () - PullRequest
0 голосов
/ 27 октября 2019

Я пытался создать plot.bar (), используя 2 значения, имеющие их в списке, но я не смог построить 3 значения.

Я пытался добавить plot.bar (x, y, z), но это не сработало.

ce_data = ce_data.drop(
            ['pchangeinOpenInterest', 'totalTradedVolume', 'impliedVolatility',  # this removes unecesssary items
             'pChange', 'totalBuyQuantity', 'totalSellQuantity', 'bidQty',
             'bidprice', 'askQty', 'askPrice', 'askQty', 'identifier', 'lastPrice', 'change', 'expiryDate',
             'underlying'], axis=1)[
            ['openInterest', 'changeinOpenInterest', 'strikePrice', 'underlyingValue']]

        style.use('ggplot')
        ce_data.to_csv('kumar.csv')

        df = pd.read_csv('kumar.csv', parse_dates=True, index_col=0)
        pivot = df.iloc[2, 3]  # this selects the strike price
        pivot_round = round(pivot, -2)  # round of the price

x = df['strikePrice'].tolist()
y = df['changeinOpenInterest'].tolist()
z = df['openInterest'].tolist()

for i in range(len(x)):
    if int(x[i]) >= pivot_round - 400:
        xleftpos = i
        break

for i in range(len(x)):
    if int(x[i]) >= pivot_round + 400:
        xrightpos = i
        break

x = x[xleftpos:xrightpos]
y = y[xleftpos:xrightpos]
z = z[xleftpos:xrightpos]

plot.bar([value for value in range(len(x))],y)

plot.set_xticks([idx + 0.5 for idx in range(len(x))])
plot.set_xticklabels(x, rotation=35, ha='right', size=10)

Я ожидаю цену страйка по осям x и y и z (изменение oi и oi) в виде баров.

1 Ответ

0 голосов
/ 27 октября 2019

IIUC, вот как я это сделаю. У него должна быть одна ось х с StrikePrice и два бара 'changeinOpenInterest' и 'openInterest'.

disp_df = df.pivot('strikePrice', 'changeinOpenInterest', 'openInterest')
disp_df.plot(kind='bar')

Вы можете добавить на график нужные вам свистки и свистки, но это позволяет избежатьмного манипуляций, которые вы сделали выше.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...