Show one value in range on TooltipHow do I sort a list of dictionaries by a value of the dictionary?How do I return multiple values from a function?How do I sort a dictionary by value?How to access environment variable values?“Large data” work flows using pandashow to show integer, not float, with hover tooltip in bokehWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Bokeh streaming axesbokeh hover multiline with datetime axisAdd tooltip to Bokeh DataTable

How useful would a hydroelectric power plant be in the post-apocalypse world?

What does this Pokemon Trainer mean by saying the player is "SHELLOS"?

What is my external HDD doing?

Why will we fail creating a self sustaining off world colony?

Advantages of using bra-ket notation

Could you fall off a planet if it was being accelerated by engines?

"nunca" placement after a verb with "no"

What would you need merely the term "collection" for pitches, but not "scale"?

What verb goes with "coup"?

ATMEGA328P-U vs ATMEGA328-PU

Which are more efficient in putting out wildfires: planes or helicopters?

What is this fluorinated organic substance?

Rear derailleur got caught in the spokes, what could be a root cause

Where to connect the fuse and why?

English idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)

Why didn't Avengers simply jump 5 years back?

Find the closest three-digit hex colour

Understanding the as-if rule, "the program was executed as written"

Why are examinees often not allowed to leave during the start and end of an exam?

Why are symbols not written in words?

Enterprise Layers and Naming Conventions

How to track mail undetectably?

Odd PCB Layout for Voltage Regulator

Does "boire un jus" tend to mean "coffee" or "juice of fruit"?



Show one value in range on Tooltip


How do I sort a list of dictionaries by a value of the dictionary?How do I return multiple values from a function?How do I sort a dictionary by value?How to access environment variable values?“Large data” work flows using pandashow to show integer, not float, with hover tooltip in bokehWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Bokeh streaming axesbokeh hover multiline with datetime axisAdd tooltip to Bokeh DataTable













0















I am learning to use the Bokeh library on Python. What I have right now is this:



source = ColumnDataSource(data=dict(x=x, counts=rates))


My x value is an array of tuples, something like this:



x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]


What I want is to have a tooltip in my graph that will display the second value of the tuple (the 1 or the 2, whichever corresponds). I created my tooltip like this:



TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]


The first one (Rate) is working fine and shows the value that I want, but the second one shows both values (A, 1) and I only want to show one of them (1). For the record this is how I am creating the figure:



p = figure(x_range=FactorRange(*x), sizing_mode='stretch_both', title="Test",toolbar_location=None, tools="", tooltips=TOOLTIPS)


Is this possible?










share|improve this question


























    0















    I am learning to use the Bokeh library on Python. What I have right now is this:



    source = ColumnDataSource(data=dict(x=x, counts=rates))


    My x value is an array of tuples, something like this:



    x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]


    What I want is to have a tooltip in my graph that will display the second value of the tuple (the 1 or the 2, whichever corresponds). I created my tooltip like this:



    TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]


    The first one (Rate) is working fine and shows the value that I want, but the second one shows both values (A, 1) and I only want to show one of them (1). For the record this is how I am creating the figure:



    p = figure(x_range=FactorRange(*x), sizing_mode='stretch_both', title="Test",toolbar_location=None, tools="", tooltips=TOOLTIPS)


    Is this possible?










    share|improve this question
























      0












      0








      0








      I am learning to use the Bokeh library on Python. What I have right now is this:



      source = ColumnDataSource(data=dict(x=x, counts=rates))


      My x value is an array of tuples, something like this:



      x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]


      What I want is to have a tooltip in my graph that will display the second value of the tuple (the 1 or the 2, whichever corresponds). I created my tooltip like this:



      TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]


      The first one (Rate) is working fine and shows the value that I want, but the second one shows both values (A, 1) and I only want to show one of them (1). For the record this is how I am creating the figure:



      p = figure(x_range=FactorRange(*x), sizing_mode='stretch_both', title="Test",toolbar_location=None, tools="", tooltips=TOOLTIPS)


      Is this possible?










      share|improve this question














      I am learning to use the Bokeh library on Python. What I have right now is this:



      source = ColumnDataSource(data=dict(x=x, counts=rates))


      My x value is an array of tuples, something like this:



      x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]


      What I want is to have a tooltip in my graph that will display the second value of the tuple (the 1 or the 2, whichever corresponds). I created my tooltip like this:



      TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]


      The first one (Rate) is working fine and shows the value that I want, but the second one shows both values (A, 1) and I only want to show one of them (1). For the record this is how I am creating the figure:



      p = figure(x_range=FactorRange(*x), sizing_mode='stretch_both', title="Test",toolbar_location=None, tools="", tooltips=TOOLTIPS)


      Is this possible?







      python bokeh






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 16:33









      plasmyplasmy

      1342 gold badges5 silver badges19 bronze badges




      1342 gold badges5 silver badges19 bronze badges




















          2 Answers
          2






          active

          oldest

          votes


















          0














          You can just split the x-array into two separate arrays so that...




          x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]



          ...becomes...




          x_1 = ["A","B","C","A","B","C"]
          x_2 = ["1","1","1","2","2","2"]



          and then supply these arrays to the CDS.



          Then in your tooltip you just reference x_2 like...




          TOOLTIPS = [("Rate", "@counts"), ("Value", "@x_2")]






          share|improve this answer






























            0














            You could use HoverTool callback like this (Bokeh v1.0.4):



            from bokeh.plotting import figure, show
            from bokeh.models import ColumnDataSource, FactorRange, HoverTool, CustomJS

            x = [('A' , '1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]
            rates = [1, 2, 3, 4, 5, 6]

            source = ColumnDataSource(data = dict(x = x, counts = rates))

            TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]
            p = figure(x_range = FactorRange(*x), sizing_mode = 'stretch_both', title = "Test", toolbar_location = None, tools = "")
            p.vbar(x = 'x', top = 'counts', width = 0.2, source = source)

            code = ''' if (cb_data.index.indices.length > 0)
            index = cb_data.index.indices[0];
            x1 = source.data.x[index][1]
            hover.tooltips[1] = ['Value', x1];
            '''
            hover = HoverTool()
            hover.tooltips = TOOLTIPS
            hover.callback = CustomJS(args = dict(source = source, hover = hover), code = code)
            p.add_tools(hover)

            show(p)


            Result:



            enter image description here






            share|improve this answer

























              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%2f55342442%2fshow-one-value-in-range-on-tooltip%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You can just split the x-array into two separate arrays so that...




              x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]



              ...becomes...




              x_1 = ["A","B","C","A","B","C"]
              x_2 = ["1","1","1","2","2","2"]



              and then supply these arrays to the CDS.



              Then in your tooltip you just reference x_2 like...




              TOOLTIPS = [("Rate", "@counts"), ("Value", "@x_2")]






              share|improve this answer



























                0














                You can just split the x-array into two separate arrays so that...




                x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]



                ...becomes...




                x_1 = ["A","B","C","A","B","C"]
                x_2 = ["1","1","1","2","2","2"]



                and then supply these arrays to the CDS.



                Then in your tooltip you just reference x_2 like...




                TOOLTIPS = [("Rate", "@counts"), ("Value", "@x_2")]






                share|improve this answer

























                  0












                  0








                  0







                  You can just split the x-array into two separate arrays so that...




                  x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]



                  ...becomes...




                  x_1 = ["A","B","C","A","B","C"]
                  x_2 = ["1","1","1","2","2","2"]



                  and then supply these arrays to the CDS.



                  Then in your tooltip you just reference x_2 like...




                  TOOLTIPS = [("Rate", "@counts"), ("Value", "@x_2")]






                  share|improve this answer













                  You can just split the x-array into two separate arrays so that...




                  x = [('A' ,'1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]



                  ...becomes...




                  x_1 = ["A","B","C","A","B","C"]
                  x_2 = ["1","1","1","2","2","2"]



                  and then supply these arrays to the CDS.



                  Then in your tooltip you just reference x_2 like...




                  TOOLTIPS = [("Rate", "@counts"), ("Value", "@x_2")]







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 20:31









                  Christopher BuhtzChristopher Buhtz

                  161 bronze badge




                  161 bronze badge





















                      0














                      You could use HoverTool callback like this (Bokeh v1.0.4):



                      from bokeh.plotting import figure, show
                      from bokeh.models import ColumnDataSource, FactorRange, HoverTool, CustomJS

                      x = [('A' , '1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]
                      rates = [1, 2, 3, 4, 5, 6]

                      source = ColumnDataSource(data = dict(x = x, counts = rates))

                      TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]
                      p = figure(x_range = FactorRange(*x), sizing_mode = 'stretch_both', title = "Test", toolbar_location = None, tools = "")
                      p.vbar(x = 'x', top = 'counts', width = 0.2, source = source)

                      code = ''' if (cb_data.index.indices.length > 0)
                      index = cb_data.index.indices[0];
                      x1 = source.data.x[index][1]
                      hover.tooltips[1] = ['Value', x1];
                      '''
                      hover = HoverTool()
                      hover.tooltips = TOOLTIPS
                      hover.callback = CustomJS(args = dict(source = source, hover = hover), code = code)
                      p.add_tools(hover)

                      show(p)


                      Result:



                      enter image description here






                      share|improve this answer



























                        0














                        You could use HoverTool callback like this (Bokeh v1.0.4):



                        from bokeh.plotting import figure, show
                        from bokeh.models import ColumnDataSource, FactorRange, HoverTool, CustomJS

                        x = [('A' , '1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]
                        rates = [1, 2, 3, 4, 5, 6]

                        source = ColumnDataSource(data = dict(x = x, counts = rates))

                        TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]
                        p = figure(x_range = FactorRange(*x), sizing_mode = 'stretch_both', title = "Test", toolbar_location = None, tools = "")
                        p.vbar(x = 'x', top = 'counts', width = 0.2, source = source)

                        code = ''' if (cb_data.index.indices.length > 0)
                        index = cb_data.index.indices[0];
                        x1 = source.data.x[index][1]
                        hover.tooltips[1] = ['Value', x1];
                        '''
                        hover = HoverTool()
                        hover.tooltips = TOOLTIPS
                        hover.callback = CustomJS(args = dict(source = source, hover = hover), code = code)
                        p.add_tools(hover)

                        show(p)


                        Result:



                        enter image description here






                        share|improve this answer

























                          0












                          0








                          0







                          You could use HoverTool callback like this (Bokeh v1.0.4):



                          from bokeh.plotting import figure, show
                          from bokeh.models import ColumnDataSource, FactorRange, HoverTool, CustomJS

                          x = [('A' , '1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]
                          rates = [1, 2, 3, 4, 5, 6]

                          source = ColumnDataSource(data = dict(x = x, counts = rates))

                          TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]
                          p = figure(x_range = FactorRange(*x), sizing_mode = 'stretch_both', title = "Test", toolbar_location = None, tools = "")
                          p.vbar(x = 'x', top = 'counts', width = 0.2, source = source)

                          code = ''' if (cb_data.index.indices.length > 0)
                          index = cb_data.index.indices[0];
                          x1 = source.data.x[index][1]
                          hover.tooltips[1] = ['Value', x1];
                          '''
                          hover = HoverTool()
                          hover.tooltips = TOOLTIPS
                          hover.callback = CustomJS(args = dict(source = source, hover = hover), code = code)
                          p.add_tools(hover)

                          show(p)


                          Result:



                          enter image description here






                          share|improve this answer













                          You could use HoverTool callback like this (Bokeh v1.0.4):



                          from bokeh.plotting import figure, show
                          from bokeh.models import ColumnDataSource, FactorRange, HoverTool, CustomJS

                          x = [('A' , '1'), ('B', '1'), ('C', '1'), ('A', '2'), ('B', '2'), ('C', '2')]
                          rates = [1, 2, 3, 4, 5, 6]

                          source = ColumnDataSource(data = dict(x = x, counts = rates))

                          TOOLTIPS = [("Rate", "@counts"), ("Value", "@x")]
                          p = figure(x_range = FactorRange(*x), sizing_mode = 'stretch_both', title = "Test", toolbar_location = None, tools = "")
                          p.vbar(x = 'x', top = 'counts', width = 0.2, source = source)

                          code = ''' if (cb_data.index.indices.length > 0)
                          index = cb_data.index.indices[0];
                          x1 = source.data.x[index][1]
                          hover.tooltips[1] = ['Value', x1];
                          '''
                          hover = HoverTool()
                          hover.tooltips = TOOLTIPS
                          hover.callback = CustomJS(args = dict(source = source, hover = hover), code = code)
                          p.add_tools(hover)

                          show(p)


                          Result:



                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 25 at 23:51









                          TonyTony

                          2,8941 gold badge5 silver badges22 bronze badges




                          2,8941 gold badge5 silver badges22 bronze badges



























                              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%2f55342442%2fshow-one-value-in-range-on-tooltip%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

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript