How to create a multi_line plot with HoverTool using Bokeh?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















From a Pandas dataframe like the one below, I'm simply trying to create a multi_line plot plus HoverTool; however, I can't find any examples similar to my specific case. Here is my sample code:



import pandas as pd
import numpy as np

# Dataframe (just toy data, this will be an import of a much larger dataset)
index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
'2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

columns = ['Argentina', 'Turkey', 'Mexico']

np.random.seed(123)
data = np.random.rand(10, 3)

df = pd.DataFrame(index=index, columns=columns, data=data)
df.index = pd.to_datetime(df.index)
df.index.name = 'Date'

# Attempt at plot (obviously doesn't work)
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.io import output_notebook, show
output_notebook()

source = ColumnDataSource(df)

p = figure(plot_height=400)
p.multi_line(xs='Date', ys=columns, source=source)

p.add_tools(HoverTool(tooltips=[('Country', '@???'),
('Date', '@Date'),
('Value', '@???')]))

show(p)


enter image description here










share|improve this question





























    0















    From a Pandas dataframe like the one below, I'm simply trying to create a multi_line plot plus HoverTool; however, I can't find any examples similar to my specific case. Here is my sample code:



    import pandas as pd
    import numpy as np

    # Dataframe (just toy data, this will be an import of a much larger dataset)
    index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
    '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

    columns = ['Argentina', 'Turkey', 'Mexico']

    np.random.seed(123)
    data = np.random.rand(10, 3)

    df = pd.DataFrame(index=index, columns=columns, data=data)
    df.index = pd.to_datetime(df.index)
    df.index.name = 'Date'

    # Attempt at plot (obviously doesn't work)
    from bokeh.plotting import figure
    from bokeh.models import ColumnDataSource, HoverTool
    from bokeh.io import output_notebook, show
    output_notebook()

    source = ColumnDataSource(df)

    p = figure(plot_height=400)
    p.multi_line(xs='Date', ys=columns, source=source)

    p.add_tools(HoverTool(tooltips=[('Country', '@???'),
    ('Date', '@Date'),
    ('Value', '@???')]))

    show(p)


    enter image description here










    share|improve this question

























      0












      0








      0








      From a Pandas dataframe like the one below, I'm simply trying to create a multi_line plot plus HoverTool; however, I can't find any examples similar to my specific case. Here is my sample code:



      import pandas as pd
      import numpy as np

      # Dataframe (just toy data, this will be an import of a much larger dataset)
      index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
      '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

      columns = ['Argentina', 'Turkey', 'Mexico']

      np.random.seed(123)
      data = np.random.rand(10, 3)

      df = pd.DataFrame(index=index, columns=columns, data=data)
      df.index = pd.to_datetime(df.index)
      df.index.name = 'Date'

      # Attempt at plot (obviously doesn't work)
      from bokeh.plotting import figure
      from bokeh.models import ColumnDataSource, HoverTool
      from bokeh.io import output_notebook, show
      output_notebook()

      source = ColumnDataSource(df)

      p = figure(plot_height=400)
      p.multi_line(xs='Date', ys=columns, source=source)

      p.add_tools(HoverTool(tooltips=[('Country', '@???'),
      ('Date', '@Date'),
      ('Value', '@???')]))

      show(p)


      enter image description here










      share|improve this question














      From a Pandas dataframe like the one below, I'm simply trying to create a multi_line plot plus HoverTool; however, I can't find any examples similar to my specific case. Here is my sample code:



      import pandas as pd
      import numpy as np

      # Dataframe (just toy data, this will be an import of a much larger dataset)
      index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
      '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

      columns = ['Argentina', 'Turkey', 'Mexico']

      np.random.seed(123)
      data = np.random.rand(10, 3)

      df = pd.DataFrame(index=index, columns=columns, data=data)
      df.index = pd.to_datetime(df.index)
      df.index.name = 'Date'

      # Attempt at plot (obviously doesn't work)
      from bokeh.plotting import figure
      from bokeh.models import ColumnDataSource, HoverTool
      from bokeh.io import output_notebook, show
      output_notebook()

      source = ColumnDataSource(df)

      p = figure(plot_height=400)
      p.multi_line(xs='Date', ys=columns, source=source)

      p.add_tools(HoverTool(tooltips=[('Country', '@???'),
      ('Date', '@Date'),
      ('Value', '@???')]))

      show(p)


      enter image description here







      python bokeh






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 19:50









      ScottPScottP

      37128




      37128
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Multi lines xs and ys should be a list of lists, that's why it didn't work.
          I replaced the multiline for 3 normal lines and it should work fine now.
          If you really want to use multi line, you should format your data like this:



          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31', 
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']
          source = ColumnDataSource(dict(
          "xs": [index, index, index],
          "ys": np.random.rand(3, 10).tolist()
          ))


          Working code with line instead of multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import output_notebook, show
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)

          df = pd.DataFrame(index=index, columns=columns, data=data)
          df['Date'] = index

          output_notebook()
          source = ColumnDataSource(df)

          p = figure(plot_height=400, x_range=index)
          p.line(x='Date', y='Argentina', source=source, color='red', legend='Argentina ', name='Argentina')
          p.line(x='Date', y='Turkey', source=source, color='blue', legend='Turkey ', name='Turkey')
          p.line(x='Date', y='Mexico', source=source, color='green', legend='Mexico ', name='Mexico')
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '$name'),
          ('Date', '@Date'),
          ('Value', '$y')]))

          show(p)


          Version with multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import show, output_notebook
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)
          df = pd.DataFrame(index=index, columns=columns, data=data)
          df_transposed = df.transpose()
          source = ColumnDataSource({"xs": [df.index.values.tolist()]*len(list(df.columns.values)), "ys": df_transposed.values.tolist(), "colors": ["red", "green", "blue"], "names": list(df.columns.values)})

          output_notebook()
          p = figure(plot_height=400, x_range=index)
          p.multi_line(xs='xs', ys='ys', color = "colors", name="names", legend="names", source=source)
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '@names'),
          ('Date', '$x'),
          ('Value', '$y')]))

          show(p)


          I only had one problem with the hover tool. It doesn't display the correct date. (Now it shows the x position, if I replaced this for "xs" it would show the whole date list)






          share|improve this answer


























          • Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

            – ScottP
            Nov 23 '18 at 11:33






          • 1





            Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

            – Jasper
            Nov 23 '18 at 14:37











          • Thanks, works for me now!

            – ScottP
            Nov 23 '18 at 15:33












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437304%2fhow-to-create-a-multi-line-plot-with-hovertool-using-bokeh%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Multi lines xs and ys should be a list of lists, that's why it didn't work.
          I replaced the multiline for 3 normal lines and it should work fine now.
          If you really want to use multi line, you should format your data like this:



          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31', 
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']
          source = ColumnDataSource(dict(
          "xs": [index, index, index],
          "ys": np.random.rand(3, 10).tolist()
          ))


          Working code with line instead of multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import output_notebook, show
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)

          df = pd.DataFrame(index=index, columns=columns, data=data)
          df['Date'] = index

          output_notebook()
          source = ColumnDataSource(df)

          p = figure(plot_height=400, x_range=index)
          p.line(x='Date', y='Argentina', source=source, color='red', legend='Argentina ', name='Argentina')
          p.line(x='Date', y='Turkey', source=source, color='blue', legend='Turkey ', name='Turkey')
          p.line(x='Date', y='Mexico', source=source, color='green', legend='Mexico ', name='Mexico')
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '$name'),
          ('Date', '@Date'),
          ('Value', '$y')]))

          show(p)


          Version with multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import show, output_notebook
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)
          df = pd.DataFrame(index=index, columns=columns, data=data)
          df_transposed = df.transpose()
          source = ColumnDataSource({"xs": [df.index.values.tolist()]*len(list(df.columns.values)), "ys": df_transposed.values.tolist(), "colors": ["red", "green", "blue"], "names": list(df.columns.values)})

          output_notebook()
          p = figure(plot_height=400, x_range=index)
          p.multi_line(xs='xs', ys='ys', color = "colors", name="names", legend="names", source=source)
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '@names'),
          ('Date', '$x'),
          ('Value', '$y')]))

          show(p)


          I only had one problem with the hover tool. It doesn't display the correct date. (Now it shows the x position, if I replaced this for "xs" it would show the whole date list)






          share|improve this answer


























          • Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

            – ScottP
            Nov 23 '18 at 11:33






          • 1





            Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

            – Jasper
            Nov 23 '18 at 14:37











          • Thanks, works for me now!

            – ScottP
            Nov 23 '18 at 15:33
















          1














          Multi lines xs and ys should be a list of lists, that's why it didn't work.
          I replaced the multiline for 3 normal lines and it should work fine now.
          If you really want to use multi line, you should format your data like this:



          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31', 
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']
          source = ColumnDataSource(dict(
          "xs": [index, index, index],
          "ys": np.random.rand(3, 10).tolist()
          ))


          Working code with line instead of multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import output_notebook, show
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)

          df = pd.DataFrame(index=index, columns=columns, data=data)
          df['Date'] = index

          output_notebook()
          source = ColumnDataSource(df)

          p = figure(plot_height=400, x_range=index)
          p.line(x='Date', y='Argentina', source=source, color='red', legend='Argentina ', name='Argentina')
          p.line(x='Date', y='Turkey', source=source, color='blue', legend='Turkey ', name='Turkey')
          p.line(x='Date', y='Mexico', source=source, color='green', legend='Mexico ', name='Mexico')
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '$name'),
          ('Date', '@Date'),
          ('Value', '$y')]))

          show(p)


          Version with multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import show, output_notebook
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)
          df = pd.DataFrame(index=index, columns=columns, data=data)
          df_transposed = df.transpose()
          source = ColumnDataSource({"xs": [df.index.values.tolist()]*len(list(df.columns.values)), "ys": df_transposed.values.tolist(), "colors": ["red", "green", "blue"], "names": list(df.columns.values)})

          output_notebook()
          p = figure(plot_height=400, x_range=index)
          p.multi_line(xs='xs', ys='ys', color = "colors", name="names", legend="names", source=source)
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '@names'),
          ('Date', '$x'),
          ('Value', '$y')]))

          show(p)


          I only had one problem with the hover tool. It doesn't display the correct date. (Now it shows the x position, if I replaced this for "xs" it would show the whole date list)






          share|improve this answer


























          • Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

            – ScottP
            Nov 23 '18 at 11:33






          • 1





            Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

            – Jasper
            Nov 23 '18 at 14:37











          • Thanks, works for me now!

            – ScottP
            Nov 23 '18 at 15:33














          1












          1








          1







          Multi lines xs and ys should be a list of lists, that's why it didn't work.
          I replaced the multiline for 3 normal lines and it should work fine now.
          If you really want to use multi line, you should format your data like this:



          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31', 
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']
          source = ColumnDataSource(dict(
          "xs": [index, index, index],
          "ys": np.random.rand(3, 10).tolist()
          ))


          Working code with line instead of multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import output_notebook, show
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)

          df = pd.DataFrame(index=index, columns=columns, data=data)
          df['Date'] = index

          output_notebook()
          source = ColumnDataSource(df)

          p = figure(plot_height=400, x_range=index)
          p.line(x='Date', y='Argentina', source=source, color='red', legend='Argentina ', name='Argentina')
          p.line(x='Date', y='Turkey', source=source, color='blue', legend='Turkey ', name='Turkey')
          p.line(x='Date', y='Mexico', source=source, color='green', legend='Mexico ', name='Mexico')
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '$name'),
          ('Date', '@Date'),
          ('Value', '$y')]))

          show(p)


          Version with multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import show, output_notebook
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)
          df = pd.DataFrame(index=index, columns=columns, data=data)
          df_transposed = df.transpose()
          source = ColumnDataSource({"xs": [df.index.values.tolist()]*len(list(df.columns.values)), "ys": df_transposed.values.tolist(), "colors": ["red", "green", "blue"], "names": list(df.columns.values)})

          output_notebook()
          p = figure(plot_height=400, x_range=index)
          p.multi_line(xs='xs', ys='ys', color = "colors", name="names", legend="names", source=source)
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '@names'),
          ('Date', '$x'),
          ('Value', '$y')]))

          show(p)


          I only had one problem with the hover tool. It doesn't display the correct date. (Now it shows the x position, if I replaced this for "xs" it would show the whole date list)






          share|improve this answer















          Multi lines xs and ys should be a list of lists, that's why it didn't work.
          I replaced the multiline for 3 normal lines and it should work fine now.
          If you really want to use multi line, you should format your data like this:



          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31', 
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']
          source = ColumnDataSource(dict(
          "xs": [index, index, index],
          "ys": np.random.rand(3, 10).tolist()
          ))


          Working code with line instead of multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import output_notebook, show
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)

          df = pd.DataFrame(index=index, columns=columns, data=data)
          df['Date'] = index

          output_notebook()
          source = ColumnDataSource(df)

          p = figure(plot_height=400, x_range=index)
          p.line(x='Date', y='Argentina', source=source, color='red', legend='Argentina ', name='Argentina')
          p.line(x='Date', y='Turkey', source=source, color='blue', legend='Turkey ', name='Turkey')
          p.line(x='Date', y='Mexico', source=source, color='green', legend='Mexico ', name='Mexico')
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '$name'),
          ('Date', '@Date'),
          ('Value', '$y')]))

          show(p)


          Version with multiline:



          from bokeh.plotting import figure
          from bokeh.models import ColumnDataSource, HoverTool
          from bokeh.io import show, output_notebook
          import pandas as pd
          import numpy as np

          index = ['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', '2018-05-31',
          '2018-06-30', '2018-07-31', '2018-08-31', '2018-09-30', '2018-10-31']

          columns = ['Argentina', 'Turkey', 'Mexico']

          np.random.seed(123)
          data = np.random.rand(10, 3)
          df = pd.DataFrame(index=index, columns=columns, data=data)
          df_transposed = df.transpose()
          source = ColumnDataSource({"xs": [df.index.values.tolist()]*len(list(df.columns.values)), "ys": df_transposed.values.tolist(), "colors": ["red", "green", "blue"], "names": list(df.columns.values)})

          output_notebook()
          p = figure(plot_height=400, x_range=index)
          p.multi_line(xs='xs', ys='ys', color = "colors", name="names", legend="names", source=source)
          p.xaxis.major_label_orientation = 0.90
          p.legend.click_policy="hide"
          p.add_tools(HoverTool(tooltips=[('Country', '@names'),
          ('Date', '$x'),
          ('Value', '$y')]))

          show(p)


          I only had one problem with the hover tool. It doesn't display the correct date. (Now it shows the x position, if I replaced this for "xs" it would show the whole date list)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 14:40

























          answered Nov 23 '18 at 9:17









          JasperJasper

          8801412




          8801412













          • Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

            – ScottP
            Nov 23 '18 at 11:33






          • 1





            Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

            – Jasper
            Nov 23 '18 at 14:37











          • Thanks, works for me now!

            – ScottP
            Nov 23 '18 at 15:33



















          • Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

            – ScottP
            Nov 23 '18 at 11:33






          • 1





            Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

            – Jasper
            Nov 23 '18 at 14:37











          • Thanks, works for me now!

            – ScottP
            Nov 23 '18 at 15:33

















          Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

          – ScottP
          Nov 23 '18 at 11:33





          Thanks Jasper, but that actually doesn't work for me. It doesn't produce the tooltips. Also, I prefer to use multi_line.

          – ScottP
          Nov 23 '18 at 11:33




          1




          1





          Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

          – Jasper
          Nov 23 '18 at 14:37





          Weird, works fine when I run it. Maybe it didn't work because I removed the output_notebook() from the answer because I wasn't running it in a notebook, or maybe we're using a different version of Bokeh? I'm using Bokeh 1.0.1. Anyways, I added the line again and added a version with multiline.

          – Jasper
          Nov 23 '18 at 14:37













          Thanks, works for me now!

          – ScottP
          Nov 23 '18 at 15:33





          Thanks, works for me now!

          – ScottP
          Nov 23 '18 at 15:33




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437304%2fhow-to-create-a-multi-line-plot-with-hovertool-using-bokeh%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?