How do I add a layer in a shape of a box to an altair plot?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?How to plot a two column pandas dataframe's elements as an histogram?Add Legend to Seaborn point plotPython pandas dataframe to better display sublistPandas: Un-nesting / flattening hierarchical dataframeHow to add x-axis on plot?How to avoid Javascript Error in altair viewing?Altair: Can't facet layered plotsRead data from a Json file and save chart to html using AltairAdding attribute “keys” to concatenated dataframes

Creating two special characters

Does grappling negate Mirror Image?

Has any country ever had 2 former presidents in jail simultaneously?

What kind of floor tile is this?

How can I write humor as character trait?

Can you use Vicious Mockery to win an argument or gain favours?

C++ copy constructor called at return

Stack Interview Code methods made from class Node and Smart Pointers

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Is there a RAID 0 Equivalent for RAM?

Why is the Sun approximated as a black body at ~ 5800 K?

How can ping know if my host is down

What (the heck) is a Super Worm Equinox Moon?

What fields between the rationals and the reals allow a good notion of 2D distance?

Is there any evidence that Cleopatra and Caesarion considered fleeing to India to escape the Romans?

What does Apple's new App Store requirement mean

How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week

Shouldn’t conservatives embrace universal basic income?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Why Shazam when there is already Superman?

Make a Bowl of Alphabet Soup

Does the reader need to like the PoV character?

Is this toilet slogan correct usage of the English language?

What is the highest possible scrabble score for placing a single tile



How do I add a layer in a shape of a box to an altair plot?


Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?How to plot a two column pandas dataframe's elements as an histogram?Add Legend to Seaborn point plotPython pandas dataframe to better display sublistPandas: Un-nesting / flattening hierarchical dataframeHow to add x-axis on plot?How to avoid Javascript Error in altair viewing?Altair: Can't facet layered plotsRead data from a Json file and save chart to html using AltairAdding attribute “keys” to concatenated dataframes













6















I am trying to add a box to be used as strikezone using a pandas dataframe with coordinates and pass it to altair.



box = pd.DataFrame()
box.loc[:,"x"] = [-0.5, 0.5, 0.5, -0.5]
box.loc[:,'y'] = [1.25, 1.25, 0.5, 0.5]


I have tried the following:



g = alt.Chart(box.loc[0:1,:]).mark_line().encode(
x = 'x',
y = 'y')

d = alt.Chart(box.loc[1:2,:]).mark_line().encode(
x = 'x',
y = 'y')

e = alt.Chart(box.loc[2:3,:]).mark_line().encode(
x = 'x',
y = 'y')

f = alt.Chart(box.loc[3:4,:]).mark_line().encode(
x = 'x',
y = 'y')

g + d + e + f


I would also like to know how to adjust the x and y axis so there is a bit of a margin around the box?










share|improve this question




























    6















    I am trying to add a box to be used as strikezone using a pandas dataframe with coordinates and pass it to altair.



    box = pd.DataFrame()
    box.loc[:,"x"] = [-0.5, 0.5, 0.5, -0.5]
    box.loc[:,'y'] = [1.25, 1.25, 0.5, 0.5]


    I have tried the following:



    g = alt.Chart(box.loc[0:1,:]).mark_line().encode(
    x = 'x',
    y = 'y')

    d = alt.Chart(box.loc[1:2,:]).mark_line().encode(
    x = 'x',
    y = 'y')

    e = alt.Chart(box.loc[2:3,:]).mark_line().encode(
    x = 'x',
    y = 'y')

    f = alt.Chart(box.loc[3:4,:]).mark_line().encode(
    x = 'x',
    y = 'y')

    g + d + e + f


    I would also like to know how to adjust the x and y axis so there is a bit of a margin around the box?










    share|improve this question


























      6












      6








      6








      I am trying to add a box to be used as strikezone using a pandas dataframe with coordinates and pass it to altair.



      box = pd.DataFrame()
      box.loc[:,"x"] = [-0.5, 0.5, 0.5, -0.5]
      box.loc[:,'y'] = [1.25, 1.25, 0.5, 0.5]


      I have tried the following:



      g = alt.Chart(box.loc[0:1,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      d = alt.Chart(box.loc[1:2,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      e = alt.Chart(box.loc[2:3,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      f = alt.Chart(box.loc[3:4,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      g + d + e + f


      I would also like to know how to adjust the x and y axis so there is a bit of a margin around the box?










      share|improve this question
















      I am trying to add a box to be used as strikezone using a pandas dataframe with coordinates and pass it to altair.



      box = pd.DataFrame()
      box.loc[:,"x"] = [-0.5, 0.5, 0.5, -0.5]
      box.loc[:,'y'] = [1.25, 1.25, 0.5, 0.5]


      I have tried the following:



      g = alt.Chart(box.loc[0:1,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      d = alt.Chart(box.loc[1:2,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      e = alt.Chart(box.loc[2:3,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      f = alt.Chart(box.loc[3:4,:]).mark_line().encode(
      x = 'x',
      y = 'y')

      g + d + e + f


      I would also like to know how to adjust the x and y axis so there is a bit of a margin around the box?







      python-3.x altair






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 at 4:39









      Suraj Kumar

      2,78231026




      2,78231026










      asked Mar 6 at 3:55









      Nicholas MareyNicholas Marey

      332




      332






















          1 Answer
          1






          active

          oldest

          votes


















          2














          I would recommend drawing all four sides with a single line chart. You can then use the domain scale parameter to adjust the axis limits (see more in the Adjusting Axis Limits section of Altair's documentation).



          Here is an example:



          import altair as alt
          import pandas as pd

          box = pd.DataFrame(
          'x': [-0.5, 0.5, 0.5, -0.5, -0.5],
          'y': [1.25, 1.25, 0.5, 0.5, 1.25]
          ).reset_index()


          alt.Chart(box).mark_line().encode(
          alt.X('x', scale=alt.Scale(domain=(-1, 1))),
          alt.Y('y', scale=alt.Scale(domain=(0, 1.5))),
          order='index'
          )


          enter image description here



          Alternatively, you can use a rect mark to avoid having to construct the rectangle's coordinates manually in the right order:



          box = pd.DataFrame('x1': [-0.5], 'x2': [0.5], 'y1': [0.5], 'y2': [1.25])

          alt.Chart(box).mark_rect(fill='none', stroke='black').encode(
          alt.X('x1', scale=alt.Scale(domain=(-1, 1))),
          alt.Y('y1', scale=alt.Scale(domain=(0, 1.5))),
          x2='x2',
          y2='y2'
          )


          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%2f55015304%2fhow-do-i-add-a-layer-in-a-shape-of-a-box-to-an-altair-plot%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









            2














            I would recommend drawing all four sides with a single line chart. You can then use the domain scale parameter to adjust the axis limits (see more in the Adjusting Axis Limits section of Altair's documentation).



            Here is an example:



            import altair as alt
            import pandas as pd

            box = pd.DataFrame(
            'x': [-0.5, 0.5, 0.5, -0.5, -0.5],
            'y': [1.25, 1.25, 0.5, 0.5, 1.25]
            ).reset_index()


            alt.Chart(box).mark_line().encode(
            alt.X('x', scale=alt.Scale(domain=(-1, 1))),
            alt.Y('y', scale=alt.Scale(domain=(0, 1.5))),
            order='index'
            )


            enter image description here



            Alternatively, you can use a rect mark to avoid having to construct the rectangle's coordinates manually in the right order:



            box = pd.DataFrame('x1': [-0.5], 'x2': [0.5], 'y1': [0.5], 'y2': [1.25])

            alt.Chart(box).mark_rect(fill='none', stroke='black').encode(
            alt.X('x1', scale=alt.Scale(domain=(-1, 1))),
            alt.Y('y1', scale=alt.Scale(domain=(0, 1.5))),
            x2='x2',
            y2='y2'
            )


            enter image description here






            share|improve this answer





























              2














              I would recommend drawing all four sides with a single line chart. You can then use the domain scale parameter to adjust the axis limits (see more in the Adjusting Axis Limits section of Altair's documentation).



              Here is an example:



              import altair as alt
              import pandas as pd

              box = pd.DataFrame(
              'x': [-0.5, 0.5, 0.5, -0.5, -0.5],
              'y': [1.25, 1.25, 0.5, 0.5, 1.25]
              ).reset_index()


              alt.Chart(box).mark_line().encode(
              alt.X('x', scale=alt.Scale(domain=(-1, 1))),
              alt.Y('y', scale=alt.Scale(domain=(0, 1.5))),
              order='index'
              )


              enter image description here



              Alternatively, you can use a rect mark to avoid having to construct the rectangle's coordinates manually in the right order:



              box = pd.DataFrame('x1': [-0.5], 'x2': [0.5], 'y1': [0.5], 'y2': [1.25])

              alt.Chart(box).mark_rect(fill='none', stroke='black').encode(
              alt.X('x1', scale=alt.Scale(domain=(-1, 1))),
              alt.Y('y1', scale=alt.Scale(domain=(0, 1.5))),
              x2='x2',
              y2='y2'
              )


              enter image description here






              share|improve this answer



























                2












                2








                2







                I would recommend drawing all four sides with a single line chart. You can then use the domain scale parameter to adjust the axis limits (see more in the Adjusting Axis Limits section of Altair's documentation).



                Here is an example:



                import altair as alt
                import pandas as pd

                box = pd.DataFrame(
                'x': [-0.5, 0.5, 0.5, -0.5, -0.5],
                'y': [1.25, 1.25, 0.5, 0.5, 1.25]
                ).reset_index()


                alt.Chart(box).mark_line().encode(
                alt.X('x', scale=alt.Scale(domain=(-1, 1))),
                alt.Y('y', scale=alt.Scale(domain=(0, 1.5))),
                order='index'
                )


                enter image description here



                Alternatively, you can use a rect mark to avoid having to construct the rectangle's coordinates manually in the right order:



                box = pd.DataFrame('x1': [-0.5], 'x2': [0.5], 'y1': [0.5], 'y2': [1.25])

                alt.Chart(box).mark_rect(fill='none', stroke='black').encode(
                alt.X('x1', scale=alt.Scale(domain=(-1, 1))),
                alt.Y('y1', scale=alt.Scale(domain=(0, 1.5))),
                x2='x2',
                y2='y2'
                )


                enter image description here






                share|improve this answer















                I would recommend drawing all four sides with a single line chart. You can then use the domain scale parameter to adjust the axis limits (see more in the Adjusting Axis Limits section of Altair's documentation).



                Here is an example:



                import altair as alt
                import pandas as pd

                box = pd.DataFrame(
                'x': [-0.5, 0.5, 0.5, -0.5, -0.5],
                'y': [1.25, 1.25, 0.5, 0.5, 1.25]
                ).reset_index()


                alt.Chart(box).mark_line().encode(
                alt.X('x', scale=alt.Scale(domain=(-1, 1))),
                alt.Y('y', scale=alt.Scale(domain=(0, 1.5))),
                order='index'
                )


                enter image description here



                Alternatively, you can use a rect mark to avoid having to construct the rectangle's coordinates manually in the right order:



                box = pd.DataFrame('x1': [-0.5], 'x2': [0.5], 'y1': [0.5], 'y2': [1.25])

                alt.Chart(box).mark_rect(fill='none', stroke='black').encode(
                alt.X('x1', scale=alt.Scale(domain=(-1, 1))),
                alt.Y('y1', scale=alt.Scale(domain=(0, 1.5))),
                x2='x2',
                y2='y2'
                )


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 7 at 4:16

























                answered Mar 6 at 4:33









                jakevdpjakevdp

                19.9k33555




                19.9k33555





























                    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%2f55015304%2fhow-do-i-add-a-layer-in-a-shape-of-a-box-to-an-altair-plot%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

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович