SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S
1
(3)
2
(9)
3
(6)
4
(2)
5
(19)
6
(7)
7
(3)
8
(5)
9
(6)
10
(13)
11
(19)
12
(16)
13
(9)
14
(17)
15
(5)
16
(12)
17
(12)
18
(5)
19
(16)
20
(10)
21
(9)
22
(3)
23
(8)
24
(5)
25
(13)
26
(11)
27
(21)
28
(9)
29
(11)
30
(6)
31
(5)




Showing 21 results of 21

From: surfcast23 <sur...@gm...> - 2012年07月27日 23:23:05
That worked beautifully thank you!
Am I reading (bins[1]-bins[0]) correctly as taking the difference between
what is in the second and first bin?
Daπid wrote:
> 
> I guess it is showing, but you have many data points, so the gaussian
> is too small down there. You have to increase its values to make both
> areas fit:
> 
> plt.plot(bins, N* N*(bins[1]-bins[0])**y, 'r--', linewidth=1)
> 
> 
> And you will get a nice gaussian fitting your data.
> 
> On Fri, Jul 27, 2012 at 11:12 PM, surfcast23 <sur...@gm...> wrote:
>>
>> Thanks for catching that sigma was still a vector! I am no longer getting
>> the
>> errors, but the best fit line is not showing up.Is there something else I
>> am
>> missing ?
>> BTW thanks for the heads up on the np.mean and np.standard functions.
>>
>> Khary
>>
>> Daπid wrote:
>>>
>>> On Fri, Jul 27, 2012 at 9:57 PM, surfcast23 <sur...@gm...>
>>> wrote:
>>>> y = mlab.normpdf( nbins, avg, sigma)
>>>> l = plt.plot(nbins, y, 'r--', linewidth=1)
>>>> plt.show()
>>>
>>> You should not change bins there, as you are evaluating the gaussian
>>> function at different values.
>>>
>>> Also, sigma is a vector, but it should be an scalar:
>>>
>>> sigma = np.sqrt((1./len(C))*(diff**2))
>>>
>>> should be
>>>
>>> sigma = np.sum(np.sqrt((1./len(C))*(diff**2))) # The sum of the
>>> previous
>>>
>>> But, much better, you can change the three lines of code by:
>>>
>>> avg=np.mean(C)
>>> sigma=np.std(C)
>>>
>>> They are way faster and more numerically accurate and stable.
>>>
>>>
>>> As a rule of thumb, if you want to do something simple, think that
>>> there should be an easy way of doing it. And if it is something people
>>> do every day (like taking the mean or the std of a vector, or loading
>>> from a txt file), there should be a very easy way of doing it. :-) And
>>> it would probably be faster and more flexible than any naive
>>> implementation.
>>>
>>>
>>> Good luck with your galaxies!
>>>
>>> ------------------------------------------------------------------------------
>>> 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
>>> Mat...@li...
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34222788.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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34222969.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Daπid <dav...@gm...> - 2012年07月27日 23:12:07
I guess it is showing, but you have many data points, so the gaussian
is too small down there. You have to increase its values to make both
areas fit:
plt.plot(bins, N*(bins[1]-bins[0])*y, 'r--', linewidth=1)
And you will get a nice gaussian fitting your data.
On Fri, Jul 27, 2012 at 11:12 PM, surfcast23 <sur...@gm...> wrote:
>
> Thanks for catching that sigma was still a vector! I am no longer getting the
> errors, but the best fit line is not showing up.Is there something else I am
> missing ?
> BTW thanks for the heads up on the np.mean and np.standard functions.
>
> Khary
>
> Daπid wrote:
>>
>> On Fri, Jul 27, 2012 at 9:57 PM, surfcast23 <sur...@gm...> wrote:
>>> y = mlab.normpdf( nbins, avg, sigma)
>>> l = plt.plot(nbins, y, 'r--', linewidth=1)
>>> plt.show()
>>
>> You should not change bins there, as you are evaluating the gaussian
>> function at different values.
>>
>> Also, sigma is a vector, but it should be an scalar:
>>
>> sigma = np.sqrt((1./len(C))*(diff**2))
>>
>> should be
>>
>> sigma = np.sum(np.sqrt((1./len(C))*(diff**2))) # The sum of the
>> previous
>>
>> But, much better, you can change the three lines of code by:
>>
>> avg=np.mean(C)
>> sigma=np.std(C)
>>
>> They are way faster and more numerically accurate and stable.
>>
>>
>> As a rule of thumb, if you want to do something simple, think that
>> there should be an easy way of doing it. And if it is something people
>> do every day (like taking the mean or the std of a vector, or loading
>> from a txt file), there should be a very easy way of doing it. :-) And
>> it would probably be faster and more flexible than any naive
>> implementation.
>>
>>
>> Good luck with your galaxies!
>>
>> ------------------------------------------------------------------------------
>> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
> --
> View this message in context: http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34222788.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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: surfcast23 <sur...@gm...> - 2012年07月27日 22:13:02
Thanks for catching that sigma was still a vector! I am no longer getting the
errors, but the best fit line is not showing up.Is there something else I am
missing ?
BTW thanks for the heads up on the np.mean and np.standard functions. 
Khary 
Daπid wrote:
> 
> On Fri, Jul 27, 2012 at 9:57 PM, surfcast23 <sur...@gm...> wrote:
>> y = mlab.normpdf( nbins, avg, sigma)
>> l = plt.plot(nbins, y, 'r--', linewidth=1)
>> plt.show()
> 
> You should not change bins there, as you are evaluating the gaussian
> function at different values.
> 
> Also, sigma is a vector, but it should be an scalar:
> 
> sigma = np.sqrt((1./len(C))*(diff**2))
> 
> should be
> 
> sigma = np.sum(np.sqrt((1./len(C))*(diff**2))) # The sum of the
> previous
> 
> But, much better, you can change the three lines of code by:
> 
> avg=np.mean(C)
> sigma=np.std(C)
> 
> They are way faster and more numerically accurate and stable.
> 
> 
> As a rule of thumb, if you want to do something simple, think that
> there should be an easy way of doing it. And if it is something people
> do every day (like taking the mean or the std of a vector, or loading
> from a txt file), there should be a very easy way of doing it. :-) And
> it would probably be faster and more flexible than any naive
> implementation.
> 
> 
> Good luck with your galaxies!
> 
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34222788.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Daπid <dav...@gm...> - 2012年07月27日 21:26:47
On Fri, Jul 27, 2012 at 9:57 PM, surfcast23 <sur...@gm...> wrote:
> y = mlab.normpdf( nbins, avg, sigma)
> l = plt.plot(nbins, y, 'r--', linewidth=1)
> plt.show()
You should not change bins there, as you are evaluating the gaussian
function at different values.
Also, sigma is a vector, but it should be an scalar:
sigma = np.sqrt((1./len(C))*(diff**2))
should be
sigma = np.sum(np.sqrt((1./len(C))*(diff**2))) # The sum of the previous
But, much better, you can change the three lines of code by:
avg=np.mean(C)
sigma=np.std(C)
They are way faster and more numerically accurate and stable.
As a rule of thumb, if you want to do something simple, think that
there should be an easy way of doing it. And if it is something people
do every day (like taking the mean or the std of a vector, or loading
from a txt file), there should be a very easy way of doing it. :-) And
it would probably be faster and more flexible than any naive
implementation.
Good luck with your galaxies!
From: surfcast23 <sur...@gm...> - 2012年07月27日 21:01:28
Just tried it with nbins set to 216 and I still get the error
surfcast23 wrote:
> 
> Hi David,
> 
> I tried your fix
> nbins = 20
> n, bins, patches = plt.hist(C, nbins, 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( nbins, avg, sigma)
> l = plt.plot(nbins, y, 'r--', linewidth=1)
> plt.show()
> 
> 
> But I am still getting the error. I printed y.shape which gave (216,) so
> does that mean that bins also needs to have 216 as a first dimension?
> Thank you
> 
> Khary
> 
> 
> Daπid wrote:
>> 
>> In the example you provide, bins is returned by the hist command,
>> whereas in your code, bins is a number that you defined as 20. So,
>> change:
>> 
>> bins = 20
>> plt.hist(C, bins, ...
>> 
>> by:
>> 
>> nbins = 20
>> n, bins, patches = plt.hist(C, nbins, ...
>> 
>> 
>> As a side comment, your data loading is too complex, and fail prone. I
>> suggest you to have a look at the numpy function for that, loadfromtxt
>> or (I like it more), genfromtxt. It would be something like:
>> 
>> data=np.genfromtxt(F, delimiter=' ')
>> C=data[:,3]
>> 
>> Much easier, and way faster.
>> 
>> 
>> Regards,
>> 
>> David.
>> 
>> On Fri, Jul 27, 2012 at 4:13 AM, surfcast23 <sur...@gm...> wrote:
>>>
>>> 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
>>> Mat...@li...
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> 
>> ------------------------------------------------------------------------------
>> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> 
>> 
> 
> 
-- 
View this message in context: http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34222567.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: surfcast23 <sur...@gm...> - 2012年07月27日 20:57:28
Hi David,
 
 I tried your fix
nbins = 20
n, bins, patches = plt.hist(C, nbins, 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( nbins, avg, sigma)
l = plt.plot(nbins, y, 'r--', linewidth=1)
plt.show()
But I am still getting the error. I printed y.shape which gave (216,) so
does that mean that bins also needs to have 216 as a first dimension? Thank
you
Khary
Daπid wrote:
> 
> In the example you provide, bins is returned by the hist command,
> whereas in your code, bins is a number that you defined as 20. So,
> change:
> 
> bins = 20
> plt.hist(C, bins, ...
> 
> by:
> 
> nbins = 20
> n, bins, patches = plt.hist(C, nbins, ...
> 
> 
> As a side comment, your data loading is too complex, and fail prone. I
> suggest you to have a look at the numpy function for that, loadfromtxt
> or (I like it more), genfromtxt. It would be something like:
> 
> data=np.genfromtxt(F, delimiter=' ')
> C=data[:,3]
> 
> Much easier, and way faster.
> 
> 
> Regards,
> 
> David.
> 
> On Fri, Jul 27, 2012 at 4:13 AM, surfcast23 <sur...@gm...> wrote:
>>
>> 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
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/ValueError%3A-x-and-y-must-have-same-first-dimension-tp34218704p34222551.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Eric F. <ef...@ha...> - 2012年07月27日 17:26:16
On 2012年07月26日 10:26 PM, Jeffrey Spencer wrote:
> Thanks, that is all good info to know. I change my data to log and
> normalize it so the logNorm is just linear actually so specifying only
> levels is fine. I'll let you know if that doesn't work properly for some
> reason.
>
> Ok, yeah I looked at pcolormesh quickly and can't remember why I chose
> originally when I wrote this to go with contourf but I use to only do
> like 10 levels. I think it might be because use a log yaxis and think it
> used to be a bit funky or couldn't get it working properly but seemed
> fine now.
>
> No, I don't want to modify the ticks but the black lines around that
> like how they are removed on the major axis in this example:
> https://dl.dropbox.com/u/13534143/example1.png
> I want to remove the black lines also around the colorbar. Not the tick
> marks. Does that make sense?
cbar.outline.set_color('none')
or
cbar.outline.set_visible(False)
>
> One more quick question out of curiosity noticing from saving plots to
> .pdf from contourf and pcolormesh vs specgram. Specgram seems to output
> the lines and text as vector graphics. Then imbeds the image. When
> outputting from pcolormesh or contourf this isn't the case. It tries to
> write the lines or something else weird happens. Can you output to .pdf
> from these and make the lines and text be vectors. Then the image output
> as an image in the pdf like in specgram. Or is there a setting to do
> this and specify the .dpi of the image in the .pdf.
Lines and text are output to pdf exactly the same by specgram, 
pcolormesh, and contourf. The difference should be only in the image 
part of the plot, which is rasterized for a specgram image and for the 
"quadmesh" produced by pcolormesh, but is a set of patches (vector 
specification, not rasterized) for contourf. Are you seeing results 
that are inconsistent with this expectation?
Eric
>
> Thanks a lot,
> Jeff
>
> On Fri, Jul 27, 2012 at 5:51 PM, Eric Firing <ef...@ha...
> <mailto:ef...@ha...>> wrote:
>
> On 2012年07月26日 9:20 PM, Jeffrey Spencer wrote:
>
> import numpy as np
> import matplotlib as mpl
> X, Y = np.meshgrid(arange(20),arange(__20))
> Z = np.arange(20*20)
> Z = Z.reshape(20,20)
> logNorm = mpl.colors.Normalize(vmin=0,__vmax=200)
> fig = mpl.pyplot.figure(10)
> ax = fig.add_subplot(111)
> surf = ax.contourf(X,Y,Z, 100, cmap=matplotlib.cm.jet, norm =
> logNorm)
> cbar = fig.colorbar(surf, shrink=0.70, norm=logNorm)
> show()
>
>
>
> OK, the basic problem here is that you are specifying 100 levels,
> which are being auto-selected to cover the actual data range; and
> the colorbar is doing what it is supposed to do, which is show the
> levels you actually have. Try leaving out the norm, and just
> specify the levels to cover what you want, more like this:
>
> surf = ax.contourf(X, Y, Z, np.arange(0, 200.1, 2), cmap=mpl.cm.jet,
> extend='both')
> cbar = fig.colorbar(surf, shrink=0.7)
>
> If you actually do want a log norm, you can pass that in to contourf
> and it will be passed on to colorbar; but most likely you should
> still specify the levels you want as an array, and not specify vmin
> and vmax in the norm. If you want log scaling, it may work better
> to simply plot the log of Z, and use the colorbar label to indicate
> that this is what you are doing.
>
> Note that with a recent change, you can use the set_under and
> set_over methods of the cmap to specify arbitrary colors, or no
> color, for the extended regions; or you can leave out the "extend"
> kwarg and not color the regions outside the range of your contour
> levels.
>
> In general, contourf is most appropriate when there is a moderate
> number of levels, well under 100; if you want that many gradations,
> then you might do better with pcolormesh or ax.pcolorfast or imshow.
> For those image-like methods, it is appropriate to use vmin and
> vmax, either directly, or in a norm.
>
> Eric
>
>
From: Mark B. <ma...@gm...> - 2012年07月27日 14:38:57
Dear List,
When I run this little file (I call it testimage.py), I get a different
answer on my Mac (the correct answer) than Windows (the wrong answer).
from pylab import *
c = ones((10,20))
ax = imshow(c)
show()
print ax.get_axes().get_position()
On my Mac I get:
run testimage
Bbox(array([[ 0.125 , 0.24166667],
 [ 0.9 , 0.75833333]]))
On Windows I get:
run testimage
Bbox(array([[ 0.125, 0.1 ],
 [0.9, 0.9 ]]))
Any thoughts? When I type the commands in at the IPython prompt it works
most of the time (on Windows), but it never works when running the file.
What in the world could be different?
mp version 1.1.0 on both systems.
Thanks for your help,
Mark
From: Daπid <dav...@gm...> - 2012年07月27日 12:13:43
In the example you provide, bins is returned by the hist command,
whereas in your code, bins is a number that you defined as 20. So,
change:
bins = 20
plt.hist(C, bins, ...
by:
nbins = 20
n, bins, patches = plt.hist(C, nbins, ...
As a side comment, your data loading is too complex, and fail prone. I
suggest you to have a look at the numpy function for that, loadfromtxt
or (I like it more), genfromtxt. It would be something like:
data=np.genfromtxt(F, delimiter=' ')
C=data[:,3]
Much easier, and way faster.
Regards,
David.
On Fri, Jul 27, 2012 at 4:13 AM, surfcast23 <sur...@gm...> wrote:
>
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Andreas H. <li...@hi...> - 2012年07月27日 08:48:57
Hi Francesco,
>>>> I'd like to place something like a 'title' inside a legend's box. In
>>>> my
>>>> specific case, I have a legend with 5 entries, arranged in 5 columns,
>>>> so
>>>> they're horizontally next to each other in one row. Now what I'd like
>>>> to
>>>> have is inside the legend's box a first row (above the legend
>>>> entries),
>>>> where I can write some text.
>>>>
>>>> Any ideas?
>>>
>>> The keyword 'title' in legend
>>> (http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend)
>>> should work.
>>
>> Almost embarassingly simple ... however: It looks like the title is in a
>> smaller font size than the other legend texts. Do I have some control
>> about the font size of the legend's title? Couldn't find anything in the
>> plt.legend docstring (I'm on 1.1.1).
>
> try:
> l = ax.legend( patches, labels, ..., title="legend title")
> t = l.get_title() #get the text object containing the title
> t.set_fontsize(30) #set the font size
>
> you can merge the last two lines together l.get_title().set_fontsize(30)
Thanks - that did the trick :)
Cheers, A.
From: Francesco M. <fra...@gm...> - 2012年07月27日 08:36:23
Hi Andreas,
2012年7月27日 Andreas Hilboll <li...@hi...>:
>> Hi Andreas,
>>
>> 2012年7月27日 Andreas Hilboll <li...@hi...>:
>>> Hi,
>>>
>>> I'd like to place something like a 'title' inside a legend's box. In my
>>> specific case, I have a legend with 5 entries, arranged in 5 columns, so
>>> they're horizontally next to each other in one row. Now what I'd like to
>>> have is inside the legend's box a first row (above the legend entries),
>>> where I can write some text.
>>>
>>> Any ideas?
>>
>> The keyword 'title' in legend
>> (http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend)
>> should work.
>
> Almost embarassingly simple ... however: It looks like the title is in a
> smaller font size than the other legend texts. Do I have some control
> about the font size of the legend's title? Couldn't find anything in the
> plt.legend docstring (I'm on 1.1.1).
try:
l = ax.legend( patches, labels, ..., title="legend title")
t = l.get_title() #get the text object containing the title
t.set_fontsize(30) #set the font size
you can merge the last two lines together l.get_title().set_fontsize(30)
Francesco
>
> Cheers, A.
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Andreas H. <li...@hi...> - 2012年07月27日 08:29:48
> Hi Andreas,
>
> 2012年7月27日 Andreas Hilboll <li...@hi...>:
>> Hi,
>>
>> I'd like to place something like a 'title' inside a legend's box. In my
>> specific case, I have a legend with 5 entries, arranged in 5 columns, so
>> they're horizontally next to each other in one row. Now what I'd like to
>> have is inside the legend's box a first row (above the legend entries),
>> where I can write some text.
>>
>> Any ideas?
>
> The keyword 'title' in legend
> (http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend)
> should work.
Almost embarassingly simple ... however: It looks like the title is in a
smaller font size than the other legend texts. Do I have some control
about the font size of the legend's title? Couldn't find anything in the
plt.legend docstring (I'm on 1.1.1).
Cheers, A.
From: Francesco M. <fra...@gm...> - 2012年07月27日 08:24:00
Hi Andreas,
2012年7月27日 Andreas Hilboll <li...@hi...>:
> Hi,
>
> I'd like to place something like a 'title' inside a legend's box. In my
> specific case, I have a legend with 5 entries, arranged in 5 columns, so
> they're horizontally next to each other in one row. Now what I'd like to
> have is inside the legend's box a first row (above the legend entries),
> where I can write some text.
>
> Any ideas?
The keyword 'title' in legend
(http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend)
should work.
Francesco
>
> Cheers, Andreas.
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Andreas H. <li...@hi...> - 2012年07月27日 08:17:37
> On Thu, Jul 26, 2012 at 06:05:39PM +0200, Andreas Hilboll wrote:
>> > Hi Andreas,
>> >
>> > 2012年7月26日 Andreas Hilboll <li...@hi...>:
>> >> Hi,
>> >>
>> >> I would like to create a figure which only contains a legend, and no
>> >> axes
>> >> at all. I would like to manually assign the colors. I found this
>> here:
>> >>
>> >> http://stackoverflow.com/a/3302666
>> >>
>> >> but from there on, I'd like to remove the axes, and put the legend
>> into
>> >> three columns.
>> >
>> > If the plot attached it's fine for you it's easy:
>> >
>> > import matplotlib.pyplot as plt
>> > ax = plt.subplot() #create the axes
>> > ax.set_axis_off() #turn off the axis
>> > .... #do patches and labels
>> > ax.legend(patches, labels, ...) #legend alone in the figure
>> > plt.show()
>> >
>> > Cheers,
>> > Francesco
>>
>> That's really easy :) I could live with this solution, applying some
>> external tool like pdfcrop to the result. Of course, it would be nicer
>> if
>> the PDF's page size would be exactly that of the legend (plus some
>> margin), so that I wouldn't have to resort to external tools ...
>>
>> Any ideas?
>>
>
> How about
>
> plt.savefig('roflcakes.png', bbox_inches='tight', pad_inches=0.1)
>
> Since the other artists are invisible, that should crop to just your
> legend. I'm assuming matplotlib updates the BoundingBox such that it
> doesn't include invisible artists.
Thanks for your help, guys! I wasn't totally happy with the 'tight'
bounding box, as the margins to the legend were not uniform on all four
sides. So I did indeed return to a subprocess.call(['pdfcrop', ...]).
Cheers, A.
From: Andreas H. <li...@hi...> - 2012年07月27日 08:15:57
Hi,
I'd like to place something like a 'title' inside a legend's box. In my
specific case, I have a legend with 5 entries, arranged in 5 columns, so
they're horizontally next to each other in one row. Now what I'd like to
have is inside the legend's box a first row (above the legend entries),
where I can write some text.
Any ideas?
Cheers, Andreas.
From: Eric F. <ef...@ha...> - 2012年07月27日 07:51:48
On 2012年07月26日 9:20 PM, Jeffrey Spencer wrote:
> import numpy as np
> import matplotlib as mpl
> X, Y = np.meshgrid(arange(20),arange(20))
> Z = np.arange(20*20)
> Z = Z.reshape(20,20)
> logNorm = mpl.colors.Normalize(vmin=0,vmax=200)
> fig = mpl.pyplot.figure(10)
> ax = fig.add_subplot(111)
> surf = ax.contourf(X,Y,Z, 100, cmap=matplotlib.cm.jet, norm = logNorm)
> cbar = fig.colorbar(surf, shrink=0.70, norm=logNorm)
> show()
OK, the basic problem here is that you are specifying 100 levels, which 
are being auto-selected to cover the actual data range; and the colorbar 
is doing what it is supposed to do, which is show the levels you 
actually have. Try leaving out the norm, and just specify the levels to 
cover what you want, more like this:
surf = ax.contourf(X, Y, Z, np.arange(0, 200.1, 2), cmap=mpl.cm.jet, 
extend='both')
cbar = fig.colorbar(surf, shrink=0.7)
If you actually do want a log norm, you can pass that in to contourf and 
it will be passed on to colorbar; but most likely you should still 
specify the levels you want as an array, and not specify vmin and vmax 
in the norm. If you want log scaling, it may work better to simply plot 
the log of Z, and use the colorbar label to indicate that this is what 
you are doing.
Note that with a recent change, you can use the set_under and set_over 
methods of the cmap to specify arbitrary colors, or no color, for the 
extended regions; or you can leave out the "extend" kwarg and not color 
the regions outside the range of your contour levels.
In general, contourf is most appropriate when there is a moderate number 
of levels, well under 100; if you want that many gradations, then you 
might do better with pcolormesh or ax.pcolorfast or imshow. For those 
image-like methods, it is appropriate to use vmin and vmax, either 
directly, or in a norm.
Eric
From: Jeffrey S. <jef...@gm...> - 2012年07月27日 07:21:02
 I am using 1.2.X and here is a minimalist example to see what happens:
Link to figure of output:
https://dl.dropbox.com/u/13534143/example.png
Example:
import numpy as np
import matplotlib as mpl
X, Y = np.meshgrid(arange(20),arange(20))
Z = np.arange(20*20)
Z = Z.reshape(20,20)
logNorm = mpl.colors.Normalize(vmin=0,vmax=200)
fig = mpl.pyplot.figure(10)
ax = fig.add_subplot(111)
surf = ax.contourf(X,Y,Z, 100, cmap=matplotlib.cm.jet, norm = logNorm)
cbar = fig.colorbar(surf, shrink=0.70, norm=logNorm)
show()
draw()
On Fri, Jul 27, 2012 at 5:00 PM, Eric Firing <ef...@ha...> wrote:
> On 2012年07月26日 7:52 PM, Jeffrey Spencer wrote:
> > I am trying to make a plot with a colorbar that has a reduced axis over
> > which the colorbar is executed.
> >
> > This is set via passing in a norm to contourf:
> > logNorm = colors.Normalize(vmax=0,vmin=-100)
> > surf = ax.contourf(X,Y,logZ, map_scale, cmap=cm.jet,
> norm=logNorm)
> >
> > The output of this will have the colorbar extend to the full range of
> > the data and not limited by the norm set:
> >
> > cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03)
> >
> > so I assumed modifying by setting the norm like this would do the trick:
> >
> > cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03,
> > norm=logNorm)
> >
> > This isn't what happens. norm has no effect. The norm is recognized but
> > not passed to ColorbarBase is my guess from doing this instead to get
> > the desired effect:
> >
> > axcb, _ = mpl.colorbar.make_axes_gridspec(ax, shrink=0.7)
> > cbar = mpl.colorbar.ColorbarBase(axcb, cmap=cm.jet,
> norm=logNorm)
> >
> >
> >
> > Is this a bug or any reason why the norm is not passed through if
> > specified in colorbar??
>
> Yes, there is a reason why it is not passed through; both the cmap and
> the norm are taken from the mappable, so that the colorbar will actually
> match the mappable. There may be a bug, but it is not immediately
> obvious to me. Please provide a complete, minimal, self-contained
> example that illustrates the problem, and specify what version of mpl
> you are using.
>
> Eric
>
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Jeffrey S. <jef...@gm...> - 2012年07月27日 07:02:12
Further after doing a little digging the code in
matplotlib.colorbar.Colorbar looks correct to me but doesn't work correctly.
It essentially ignores the norm value because always sets the norm to the
norm for the contour plot (eg. mappable.norm) which this is the same norm
with vmin and vmax values I want to use anyway. It seems as though somehow
instead it uses the vmin and vmax not from the norm but from the actual
data.
So from the code below it would use vmin and vmax from the mappable object
(eg. surf) which are (-152,0). It won't use surf.norm vmin and vmax values
which are desired (-100,0). I couldn't find where this mistake occurs
because looked right to me from prodding around but let me know.
____________________________________________
Jeff Spencer
Department of Electrical and Electronic Engineering
The University of Melbourne
jef...@gm...
On Fri, Jul 27, 2012 at 3:52 PM, Jeffrey Spencer <jef...@gm...>wrote:
> I am trying to make a plot with a colorbar that has a reduced axis over
> which the colorbar is executed.
>
> This is set via passing in a norm to contourf:
> logNorm = colors.Normalize(vmax=0,vmin=-100)
> surf = ax.contourf(X,Y,logZ, map_scale, cmap=cm.jet, norm=logNorm)
>
> The output of this will have the colorbar extend to the full range of the
> data and not limited by the norm set:
>
> cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03)
>
> so I assumed modifying by setting the norm like this would do the trick:
>
> cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03,
> norm=logNorm)
>
> This isn't what happens. norm has no effect. The norm is recognized but
> not passed to ColorbarBase is my guess from doing this instead to get the
> desired effect:
>
> axcb, _ = mpl.colorbar.make_axes_gridspec(ax, shrink=0.7)
> cbar = mpl.colorbar.ColorbarBase(axcb, cmap=cm.jet, norm=logNorm)
>
>
>
> Is this a bug or any reason why the norm is not passed through if
> specified in colorbar??
>
From: Eric F. <ef...@ha...> - 2012年07月27日 07:00:24
On 2012年07月26日 7:52 PM, Jeffrey Spencer wrote:
> I am trying to make a plot with a colorbar that has a reduced axis over
> which the colorbar is executed.
>
> This is set via passing in a norm to contourf:
> logNorm = colors.Normalize(vmax=0,vmin=-100)
> surf = ax.contourf(X,Y,logZ, map_scale, cmap=cm.jet, norm=logNorm)
>
> The output of this will have the colorbar extend to the full range of
> the data and not limited by the norm set:
>
> cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03)
>
> so I assumed modifying by setting the norm like this would do the trick:
>
> cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03,
> norm=logNorm)
>
> This isn't what happens. norm has no effect. The norm is recognized but
> not passed to ColorbarBase is my guess from doing this instead to get
> the desired effect:
>
> axcb, _ = mpl.colorbar.make_axes_gridspec(ax, shrink=0.7)
> cbar = mpl.colorbar.ColorbarBase(axcb, cmap=cm.jet, norm=logNorm)
>
>
>
> Is this a bug or any reason why the norm is not passed through if
> specified in colorbar??
Yes, there is a reason why it is not passed through; both the cmap and 
the norm are taken from the mappable, so that the colorbar will actually 
match the mappable. There may be a bug, but it is not immediately 
obvious to me. Please provide a complete, minimal, self-contained 
example that illustrates the problem, and specify what version of mpl 
you are using.
Eric
From: Jeffrey S. <jef...@gm...> - 2012年07月27日 05:52:45
I am trying to make a plot with a colorbar that has a reduced axis over
which the colorbar is executed.
This is set via passing in a norm to contourf:
 logNorm = colors.Normalize(vmax=0,vmin=-100)
 surf = ax.contourf(X,Y,logZ, map_scale, cmap=cm.jet, norm=logNorm)
The output of this will have the colorbar extend to the full range of the
data and not limited by the norm set:
cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03)
so I assumed modifying by setting the norm like this would do the trick:
cbar = fig.colorbar(surf, shrink=0.70, aspect=36, fraction=.15,pad=.03,
norm=logNorm)
This isn't what happens. norm has no effect. The norm is recognized but not
passed to ColorbarBase is my guess from doing this instead to get the
desired effect:
 axcb, _ = mpl.colorbar.make_axes_gridspec(ax, shrink=0.7)
 cbar = mpl.colorbar.ColorbarBase(axcb, cmap=cm.jet, norm=logNorm)
Is this a bug or any reason why the norm is not passed through if specified
in colorbar??
From: surfcast23 <sur...@gm...> - 2012年07月27日 03:13:08
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.

Showing 21 results of 21

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /