On 03/30/2011 05:01 AM, Paul Ivanov wrote:
> Michael Droettboom, on 2011-03-29 10:12,  wrote:
>> On 03/29/2011 09:08 AM, xyz wrote:
>>> Hi,
>>> X and Y values are stored in a dict whereas X is the key and Y is the
>>> value in the following code:
>>>
>>> import matplotlib.pyplot as plt
>>>
>>> data = {4: 3, 5: 4, 6: 5, 7: 4, 8: 5}
>>>
>>> print data
>>> for i in sorted(data.keys()):
>>>        print i
>>>
>>> How is possible to use plot with a dict in order to get a similar
>>> picture like this
>>> http://matplotlib.sourceforge.net/_images/invert_axes.png .
>> In this case, you should be able to use:
>>
>> plt.plot(data.items())
> For me, that line produces two lines with the abscissa going from
> 0 to 4. In other words, plt.plot(data.items()) ends up being
> equivalent to plt.plot(data.values());plt.plot(data.keys())
>
> I think what xyz wants is this:
>
> x,y = zip(*sorted(data.items()))
> plt.plot(x,y)
>
> I think of the * in front of arguments to zip as being the pull
> tab or slider of the zipper (since it's at the top, you'll be
> pulling it down, or unzipping): see
> http://docs.python.org/library/functions.html#zip
>
> best,
>
Thank you it works.

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to