1

Code for two graphs. Ran this code a couple of times, and for some reason all that's showing up is the histogram. It's also important to mention that I am using Spyder IDE as well, if that makes any difference. Oh....and I've also tried graph|hist... but nothing

    import altair as alt
    import pandas as pd
   
    #import csv
    acs = pd.read_csv('C:/Users/Andrew/anaconda3/mydata/acs2020.csv')
    acs.head()
    
    
    interval = alt.selection_interval()

    #build point graph
    graph = alt.Chart(acs).mark_point(opacity=1).encode(
        x = ('Trade #'),
        y = ('Balance'),
        color = alt.Color('Item',scale=alt.Scale(scheme='tableau10')),
        tooltip = [alt.Tooltip('Type'),
                   alt.Tooltip('Profit'),
                   alt.Tooltip('Ticket:N')
                  ]
    ).properties(
        width = 900
    )

    #build histogram
    hist = alt.Chart(acs).mark_bar().encode(
        x = 'count()',
        y = 'Item',
        color = 'Item'
    ).properties(
        width = 800,
        height = 80
    ).add_selection(
        interval
    )
    #show graphs
    graph&hist.show()
truee
  • 51
  • 7
  • 1
    Thanks for joining stack overflow. One of the requirements for a post is that it should be easily reproducible for those looking at it. Right now you are linking to a file that is inside of your local computer. This makes it hard for any of us to reproduce the issue. I would recommend creating a minimum reproducible example of the graph you are trying to make with an open source dataset that you can pull in from github or a package like seaborn. This will likely improve your response rate a ton. – WolVes Jan 04 '21 at 19:20
  • Ok, duly noted. Thanks for the input – truee Jan 04 '21 at 20:55

1 Answers1

0

You need to add parentheses to the last line: (graph & hist).show().


Explanation: when you write something like

graph&hist.show()

Python dictates the order of operations, and method calls have higher precedence than binary operators. This means that it is equivalent to:

(graph) & (hist.show())

You are showing the hist chart, and then concatenating the return value of the show() method, which is None, to the graph chart, which will result in a ValueError when the histogram chart is closed.

Instead, if you want to show the result of the graph & hist operation, you need to use parentheses to indicate this:

(graph & hist).show()
jakevdp
  • 77,104
  • 11
  • 125
  • 160