Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:10:11+00:00 2026-05-31T22:10:11+00:00

So I’m trying to plot 2 different arrays of the same dimensions using python’s

  • 0

So I’m trying to plot 2 different arrays of the same dimensions using python’s matplotlib. This is the code I currently have:

from numpy import *
from pylab import *
import matplotlib.pyplot as plt
p, pdot, s400, dist=loadtxt("cc45list.txt", usecols=(1,2,3,4), unpack=True)
for i in arange(0,45,1):
 k = (s400*(dist**2))/((p**1)*(pdot**0.5))
 kbar=sum(k)
 var=abs(k-kbar)
 x=((p**1)*(pdot**0.5))
 y=s400*(dist**2)

kbararray=ones((1,45))*kbar

I’m trying to plot a simple line with the xaxis being x and the yaxis being kbararray (which is just an array of the same value calculated in the loop). I tried using this bit of matplotlib which has worked in the past for my other plots:

plot(x,kbararray)

But I keep end up recieveing this error message:

Traceback (most recent call last):
File "C:\PortablePython_1.1_py2.6.1\App\April_2010\graphing lines.py", line 3, in <module>
plot ( range(0,11),[9,4,5,2,3,5,7,12,2,3],'.-',label='sample1' )
File "C:\PortablePython_1.1_py2.6.1\App\Lib\site-packages\matplotlib\pyplot.py", line 2141, in plot
ret = ax.plot(*args, **kwargs)
File "C:\PortablePython_1.1_py2.6.1\App\Lib\site-packages\matplotlib\axes.py", line 3432, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\PortablePython_1.1_py2.6.1\App\Lib\site-packages\matplotlib\axes.py", line 311, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\PortablePython_1.1_py2.6.1\App\Lib\site-packages\matplotlib\axes.py", line 288, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\PortablePython_1.1_py2.6.1\App\Lib\site-packages\matplotlib\axes.py", line 228, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension

From what I’ve researched this error usually comes up if you try to plot 2 arrays of different dimensions but I’m sure mine are of the same dimension, right? So why would I be getting this error? Sorry if this is a basic question/answered elsewhere but I couldn’t find anything. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:10:12+00:00Added an answer on May 31, 2026 at 10:10 pm

    The problem is in this line:

    kbararray=ones((1,45))*kbar
    

    You see, you’re declaring kbararray as having shape (1, 45), which is not the same shape as the x array, which has shape (,45).
    If you want kbararray to have the same shape as x, you can use:

    kbararray=ones_like(x)*kbar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.