I want to display multiple datasets in one graph.
But i can't seem to get the y axis to work and get the following error: ValueError: x and y must have same first dimension, but have shapes (2,) and (6060000,)
Since I am still a beginner and i copied parts of my code from different sources, my code is most likely pretty bad at some places.
I never asked any pandas/matplotlib questions, so i hope this is reproducible.
The dataframe has many columns, but only a small subset have been provided in the code sample.
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
channel_data = pd.DataFrame({'Creation date': ['2014-01-02', '2013-09-11', '2007-08-19'], 'Subscriber count': [6060000, 4110000, 4440000 ]})
# get x and y from first channel
now = str(dt.datetime.now())
now = now[:10]
dates = [channel_data["Creation date"][0], now]
dates2 = [channel_data["Creation date"][1], now]
dates3 = [channel_data["Creation date"][2], now]
x1 = [dt.datetime.strptime(d,'%Y-%m-%d').date() for d in dates]
x2 = [dt.datetime.strptime(d,'%Y-%m-%d').date() for d in dates2]
x3 = [dt.datetime.strptime(d,'%Y-%m-%d').date() for d in dates3]
# PROBLEM HERE
y1 = range(len(x1)) # i got the x axis to work but am having problems with this part
y2 = range(len(x2))
y3 = range(len(x3))
#y1 = range(0, channel_data["Subscriber count"][0])
# this was my idea of displaying the data (y-axis)
# -----------------------------------------------------------
plt.figure(figsize=(10, 5))
plt.title("Channel growth over time [USD]", fontdict={"fontweight": "bold"})
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
plt.plot(x1, y1, "b.-", label="Carwow") #b.- to choose color=blue, pointer=. , line=normal line
plt.plot(x2, y2, "r.-", label="Doug Demuro")
plt.plot(x3, y3, "g.-", label="Scotty Kilmer")
plt.xlabel("Date", fontdict={"fontsize": 13})
plt.ylabel("Subscribers", fontdict={"fontsize": 12})
plt.legend()
plt.show()
The first image shows the current graph (with wrong y values).
The second image shows a scetch of how i want to display the data.
I know this is a lot to ask at once but maybe just has an idea or a direction which i could go. Tried out a bunch of stuff but nothing worked.
Thank you for reading.


