Hi 
I have a code to plot a histogram and I am trying to add a best fit line
following this example

http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo.html

but run into this error

Traceback (most recent call last):
  File "/home/Astro/count_Histogram.py", line 54, in <module>
    l = plt.plot(bins, y, 'r--', linewidth=1)
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2467, in
plot
    ret = ax.plot(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 3893, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 322, in
_grab_next_args
    for seg in self._plot_args(remaining, kwargs):
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 300, in
_plot_args
    x, y = self._xy_from_xy(x, y)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 240, in
_xy_from_xy
    raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension

My Code 

import matplotlib.pyplot as plt
import math
import numpy as np
import mpl_toolkits.mplot3d.axes3d
import matplotlib.mlab as mlab

counts = []
F = '/home/Astro/outfiles/outmag21_5dr_38_68.txt'
f = open(F)
for line in f:
 if line != ' ':      
    columns = line.split() 
    count = columns[3]     
    count = int(count)
    counts.append(count)
    C  = np.array(counts, dtype=float)
    
avg = sum(C)/len(C)
diff = C-avg
sigma = np.sqrt((1./len(C))*(diff**2))

bins = 20
plt.hist(C, bins, range=None, normed=False, weights=None, cumulative=False,
bottom=None, histtype='bar', align='mid', orientation='vertical',
rwidth=None, log = False, color=None, label=None)
plt.title("")
plt.text(25,20,'M < -21.5' '\n' 'N Halos 3877' '\n' 'Length Cell 38.68Mpc'
'\n' 'N Cells 269' '\n' 'Avg Halo per Cell 14.35 ')
plt.xlabel("Halos/Cell")
plt.ylabel("Number Cells with N Halos")
y = mlab.normpdf( bins, avg, sigma)
print(len(y))
l = plt.plot(bins, y, 'r--', linewidth=1)
plt.show()


My first question is do x and y refer to the values in  l = plt.plot(bins,
y, 'r--', linewidth=1) which for my case are bins and y?
if that is the case how can I get then to be the same first dimension?
-- 
View this message in context: 
http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34218704.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to