Question: Implement the chart visualization code. Specifically, complete generateAPTVis ( . . . ) as described. Given a dataframe, and the augmented ordering ( we '

Implement the chart visualization code. Specifically, complete generateAPTVis(...) as described. Given a dataframe, and the "augmented" ordering (we'll use selectEncodings to do this), return an Altair chart using the specified encodings. You may implement additional additional "helper" functions if needed. def generateAPTVis(varbs,indf, hasEncodings=False):input: indf -- the dataframe to encode. The assumption is that variables in varbsinput: hasEncodings -- if the varbs data already has the encoding column (useful for testing)we assume each element in varbs already has an 'encoding' keyexceptions: EncodingException if there is an encoding failureif (not hasEncodings):
varbs = selectEncodings(varbs)toRet = alt.Chart(indf)return toRet order =[{"variable":"q1","type":"Q"},
{"variable":"q2","type":"Q"},
{"variable":"o1","type":"0"}]
display(selectEncodings(order))
generateAPTVis(order,testingFrame)
For example, if the specification says:
[{'variable': 'q1', 'type': 'Q', 'encoding': 'x'},
{'variable': 'q2', 'type': 'Q', 'encoding': 'y'},
{'variable': 'o1', 'type': 'O', 'encoding': 'saturation'}]
we want a visualization that looks something like:
Part 2.3(30 points)
Implement the chart visualization code. Specifically, complete generateAPTVis (...) as described. Given a dataframe, and the "augmented" ordering
(we'll use selectEncodings to do this), return an Altair chart using the specified encodings. You may implement additional additional "helper" functions
if needed.
For example, if the specification says:
[{'variable': 'q1', 'type': 'Q', 'encoding': 'x'},
{'variable': 'q2', 'type': 'Q', 'encoding': 'y'},
{'variable': 'o1', 'type': '0', 'encoding': 'saturation'}]
we want a visualization that looks something like:
Hints
You might want to find a way of creating Altair visualizations using loops (see how to "extend" charts in Part 1 above)
For colors, we recommend looking at the documentation for alt.Scale.
If you're not using "area" you might find that the points are quite small. We suggest hard coding a larger value so the points are visible.
Points are not filled, you might want to fill them so they are easier to read
def generateAPTVis(varbs,indf,hasEncodings=False):
# input: varbs -- the variables we want to encode in the format describe above
# input: indf -- the dataframe to encode. The assumption is that variables in varbs
# map to columns in indf
# input: hasEncodings -- if the varbs data already has the encoding column (useful for testing)
# default is False, in which case we will call selectEncodings, if true
# we assume each element in varbs already has an 'encoding' key
# return: an approriate Altair vis
# exceptions: EncodingException if there is an encoding failure
# find the encodings
if (not hasEncodings):
varbs = selectEncodings(varbs)
# modify the following code as needed
toRet = alt.Chart(indf)
# YOUR CODE HERE
return toRet
# here's a sample test. You should expand on this to make sure your function works more generally
order =[{"variable":"q1","type":"Q"},
{"variable":"q2","type":"Q"},
{"variable":"o1","type":"O"}]
display(selectEncodings(order))
generateAPTVis(order,testingFrame)
Implement the chart visualization code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!