Python Forum
ValueError: x and y must have same first dimension, but have shapes (11,) and (15406,
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: x and y must have same first dimension, but have shapes (11,) and (15406,
#9
is it np.array is up to you. it can be pandas dataframe or simple list
e.g.


import datetime as dt
import pandas as pd 
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import random

days = mdates.HourLocator(byhour=(0, 12))   # every 12 hours
hours = mdates.HourLocator()

df = pd.read_excel('data.xlsx')
 
fig, ax = plt.subplots(figsize=(8, 6))
ax.xaxis.set_major_locator(days)
ax.xaxis.set_major_formatter(mdates.DateFormatter("%m-%d %H:%M"))
ax.xaxis.set_minor_locator(hours)
ax.plot(df.x, df.y, 'bo-')
ax.set(title='Active Calls', ylabel='Calls', xlabel='Time')
ax.grid()
 
ax.xaxis_date() # Default date formatter
fig.autofmt_xdate()
 
plt.show()
   


import datetime as dt
import pandas as pd 
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import random

df = pd.read_excel('data.xlsx')
time = mdates.drange(dt.datetime(2021, 3, 1, 0, 0, 0), dt.datetime(2021, 3, 3, 1, 0, 0),
                     dt.timedelta(hours=6))
 
fig, ax = plt.subplots(figsize=(8, 6))
plt.xticks(time)
ax.xaxis.set_major_formatter(mdates.DateFormatter("%m-%d %H:%M"))
ax.plot(df.x, df.y, 'bo-')
ax.set(title='Active Calls', ylabel='Calls', xlabel='Time')
ax.grid()
 
ax.xaxis_date() # Default date formatter
fig.autofmt_xdate()
 
plt.show()
   
hobbyist likes this post

Attached Files

.xlsx   data.xlsx (Size: 5.57 KB / Downloads: 240)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: ValueError: x and y must have same first dimension, but have shapes (11,) and (15406, - by buran - Mar-16-2021, 10:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I design shapes on a curve in python? mervea 2 872 Sep-14-2023, 01:04 PM
Last Post: Pedroski55
  Array dimension don't match asja2010 0 1,138 Feb-23-2023, 04:22 PM
Last Post: asja2010
  x and y must have same first dimension, but have shapes (1,) and (50,) asja2010 5 2,744 Jan-12-2023, 07:24 PM
Last Post: deanhystad
  Shapes in Video finndude 0 723 Oct-07-2022, 03:30 PM
Last Post: finndude
  Shapes over video in tkinter finndude 1 1,005 Oct-04-2022, 06:14 PM
Last Post: deanhystad
  operands could not be broadcast together with shapes (337,451) (225,301) kevinabbot 0 1,605 Dec-14-2021, 04:02 PM
Last Post: kevinabbot
  Strange error ValueError: dimension mismatch Anldra12 0 2,020 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  ValueError: dimension mismatch Anldra12 0 3,456 Jul-17-2021, 04:46 PM
Last Post: Anldra12
  Error When Plotting ValueError: x and y must have same first dimension JoeDainton123 1 9,169 Oct-04-2020, 12:58 PM
Last Post: scidam
  Wrong dimension for my plot Jemeronimo 1 2,056 Apr-25-2019, 06:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020