0

For example, the following displays two plots. How can I draw them in a single plot?

import pandas as pd
import pandas_bokeh
pd.set_option('plotting.backend', 'pandas_bokeh')
pandas_bokeh.output_notebook()

pd.Series(np.random.randint(0, 7, size=10)).plot(kind='line')
pd.Series(np.random.randint(0, 3, size=10)).plot(kind='bar')

enter image description here

Kibeom Kim
  • 471
  • 1
  • 5
  • 12

1 Answers1

0

I suggest to use bokeh, because as far as I know has pandas-bokeh no option to join to plots and I don't want to show a workaround.

Here is a plain bokeh example which is close to the your output:

import pandas as pd
from bokeh.plotting import figure, show, output_notebook
output_notebook()

s1 = pd.DataFrame(np.random.randint(0, 7, size=10), columns=['line'])
s2 = pd.DataFrame(np.random.randint(0, 3, size=10), columns=['bar'])

p = figure(width=300, height=300)
p.line(x='index', y='line', color='blue', alpha=0.5, source=s1, legend_label='line')
p.vbar(x='index', top='bar', color='red', alpha=0.5, source=s2, legend_label='bar')
p.legend.click_policy='hide'
show(p)

example

mosc9575
  • 5,618
  • 2
  • 9
  • 32
  • Thanks for the answer! Though this requires substantially more boilerplates and it would be great if it's as simple as the original code for me. Just filed a feature request https://github.com/PatrikHlobil/Pandas-Bokeh/issues/121 . – Kibeom Kim Dec 25 '21 at 06:53