I am getting started with visualization, but right at the start I am having a serious conceptual problem. Repeatedly, I get the error ‘x and y must be the same size’ / ‘array must be the same length’ / ‘have the same shape’. I just fundamentally don’t understand why that must be so. Let me give you an example:
I go bowling once a day, every day, for a month. I keep track of my scores. I want to know what day of the week I get the best scores. I want to make a chart with days of the week on the y axis, and dates of the month on the x axis. My scores go in each intersection of these two axes. There are 7 days in a week, and 28 (just to ignore a few days getting more turns) days in a month. Clearly, x and y are not the same length, and yes, I get an error. But so what? Why is that an issue? Every day and date will get a score. I would think it is much more common for x and y to not be the same length in the real world.
For example, how would anyone ever be able to do a long running time series? So clearly there is something fundamental about charts that I just am not grasping. Can you tell me what it is? Thanks.
@seanowen
Yes, and bars, too...
import altair as alt
import pandas as pd
data = pd.DataFrame({'y': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
'x':[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
27,28]})
ValueError Traceback (most recent call last)
/tmp/ipykernel_233189/3256713105.py in <module>
.....snip...
~/.virtualenvs/PapasBook/lib/python3.9/site-packages/pandas/core/internals/construction.py in _extract_index(data)
633 lengths = list(set(raw_lengths))
634 if len(lengths) > 1:
--> 635 raise ValueError("All arrays must be of the same length")
636
637 if have_dicts:
ValueError: All arrays must be of the same length