For a deeper look into our Eikon Data API, look into:

# question

Accepted
1 0 1 1

## Eikon Codebook - Matplotlib Bar Chart Open Interest by Strike

Hi Everyone,

I am using python in codebook and trying to graph open interest by strike in a chart. I am trying to get it to illustrate the calls in one color and the puts in another color. I can get as far as the graph, however, I can not figure out how to break out the PUTCALLIND to illustrate put vs call with different colors. Any guidance would be greatly apprecaited. Thanks!

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline

import seaborn as sns

plt.style.use('seaborn-dark-palette')

import warnings

warnings.filterwarnings('ignore')

import eikon as tr

tr.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')

df, e= tr.get_data('0#IBM*.U',fields = ['PUTCALLIND','STRIKE_PRC','OPINT_1'])

df

df1 = df.groupby(['STRIKE_PRC']).sum()

df1.plot(figsize=(12,5), title='Total Open Interest Per Strike Price', kind='bar'); 1615833642088.png (10.8 KiB)
1615833593538.png (24.9 KiB) Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Accepted
28.3k 30 11 15

Hello @brandonwarnecke,

Try:

```import numpy as
import pandas as
import matplotlib.pyplot as p
%matplotlib inli
import seaborn as sns

plt.style.use('seaborn-dark-palette')

import warnings

warnings.filterwarnings('ignore')

import eikon as tr

tr.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')

df, e= tr.get_data('0#IBM*.U',fields = ['PUTCALLIND','STRIKE_PRC','OPINT_1'])

df1 = df.groupby(['STRIKE_PRC','PUTCALLIND']).sum()

df1.unstack().plot(figsize=(12,5), title='Total Open Interest Per Strike Price', kind='bar', color =['black','red']);```

For me results in: putcall.gif (13.6 KiB) Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8045355,"math_prob":0.74863434,"size":848,"snap":"2022-27-2022-33","text_gpt3_token_len":220,"char_repetition_ratio":0.09241706,"word_repetition_ratio":0.0,"special_character_ratio":0.2476415,"punctuation_ratio":0.15568863,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96123827,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,2,null,2,null,null,null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-01T23:47:20Z\",\"WARC-Record-ID\":\"<urn:uuid:61d872f7-0dc1-48da-b2e5-3a5a0be551f3>\",\"Content-Length\":\"147051\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:54d2e095-559f-4bef-aaaa-43bea50466bf>\",\"WARC-Concurrent-To\":\"<urn:uuid:53785e49-0c5e-4484-aae3-25bf8eec3ce3>\",\"WARC-IP-Address\":\"3.224.0.123\",\"WARC-Target-URI\":\"https://community.developers.refinitiv.com/questions/75069/eikon-codebook-matplotlib-bar-chart-open-interest.html\",\"WARC-Payload-Digest\":\"sha1:VLHXFOAOEAHIMNJVNI5WV6PTBDLEK5VP\",\"WARC-Block-Digest\":\"sha1:KY5BI5WKOE7LCSZWFG4K2FLID7ODIJZJ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103947269.55_warc_CC-MAIN-20220701220150-20220702010150-00006.warc.gz\"}"}