Issue
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()
Solution
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()
Answered By - jakevdp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.