SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: xyz <mi...@op...> - 2011年03月29日 13:11:12
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 .
Thank you in advance.
From: Michael D. <md...@st...> - 2011年03月29日 14:15:16
In this case, you should be able to use:
plt.plot(data.items())
Mike
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 .
>
> Thank you in advance.
>
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
-- 
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA
From: Paul I. <piv...@gm...> - 2011年03月29日 19:01:30
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,
-- 
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 
From: xyz <mi...@op...> - 2011年03月30日 12:55:08
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.
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 によって変換されたページ (->オリジナル) /