Matplotlib: An apparent error

35 views
Skip to first unread message

Owen Densmore

unread,
Aug 21, 2011, 4:32:20 PM8/21/11
to sage-s...@googlegroups.com
I work with a group, many of whom use the numpy, scipy, matplotlib stack, while I much prefer using Sage.  So I modified Sage to let me use the matplotlib GUI which is not include in the standard Sage release.

To do so, I followed the instructions for installing the matplotlib backend
.. which for me required only setting the two env variables and running
    sage -i matplotlib

To test this out, I actually installed the numpy, scipy, matplotlib as well, and in both, ran this test from a Machine Learning book, using "ipython" and "sage" command line .. i.e. no arguments like -pylab etc:
import numpy as np
import matplotlib.pyplot as plt
import os
os.chdir(os.path.expanduser("~/src/ML/2 Linear"))
pima = np.loadtxt('./pima-indians-diabetes.data',delimiter=',')
indices0 = np.where(pima[:,8]==0)
indices1 = np.where(pima[:,8]==1)
plt.plot(pima[indices0,0],pima[indices0,1],'go');
plt.plot(pima[indices1,0],pima[indices1,1],'rx');
plt.show()

The results look alike, but the axes appear to lack the lowest decimal value.  So for 10, 11, 12 ... I see 1, 1, 1!


Here are the plots, the first from the scipy install, the second from sage.  I'd like to know if this is a mistake on my part or a bug that needs to be reported.

My environment is 
sage -v -> Detected SAGE64 flag, Building Sage on OS X in 64-bit mode, Sage Version 4.7, Release Date: 2011-05-23

        -- Owen

Python001.png


Preview003.png



Python001.png
Preview003.png

William Stein

unread,
Aug 21, 2011, 7:54:14 PM8/21/11
to sage-s...@googlegroups.com


On Sunday, August 21, 2011, Owen Densmore <ow...@backspaces.net> wrote:
> I work with a group, many of whom use the numpy, scipy, matplotlib stack, while I much prefer using Sage.  So I modified Sage to let me use the matplotlib GUI which is not include in the standard Sage release.
> To do so, I followed the instructions for installing the matplotlib backend
>     http://wiki.sagemath.org/sage_matlab
> .. which for me required only setting the two env variables and running
>     sage -i matplotlib
> To test this out, I actually installed the numpy, scipy, matplotlib as well, and in both, ran this test from a Machine Learning book, using "ipython" and "sage" command line .. i.e. no arguments like -pylab etc:
>

Obvious question: are you using exactly the same versions of numpy, etc., in both of your tests?



> import numpy as np
> import matplotlib.pyplot as plt
> import os
> os.chdir(os.path.expanduser("~/src/ML/2 Linear"))
> pima = np.loadtxt('./pima-indians-diabetes.data',delimiter=',')
> indices0 = np.where(pima[:,8]==0)
> indices1 = np.where(pima[:,8]==1)
> plt.plot(pima[indices0,0],pima[indices0,1],'go');
> plt.plot(pima[indices1,0],pima[indices1,1],'rx');
> plt.show()
>
> The results look alike, but the axes appear to lack the lowest decimal value.  So for 10, 11, 12 ... I see 1, 1, 1!
> The dataset is on this public site: http://archive.ics.uci.edu/ml/datasets/Pima+Indians+Diabetes
> Here are the plots, the first from the scipy install, the second from sage.  I'd like to know if this is a mistake on my part or a bug that needs to be reported.
> My environment is 
> sage -v -> Detected SAGE64 flag, Building Sage on OS X in 64-bit mode, Sage Version 4.7, Release Date: 2011-05-23
>         -- Owen
>
>
>
>
>
>
>
> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com <sage-support%2Bunsu...@googlegroups.com>
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>

--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Rajeev Singh

unread,
Aug 22, 2011, 7:28:46 AM8/22/11
to sage-s...@googlegroups.com

--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to sage-support...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

also the y-axis has 5, 10, 15, 20 instead of 50, 100, 150, 200. just pointing out since u didn't mention it.

Rajeev
Preview003.png
Python001.png

Jason Grout

unread,
Aug 22, 2011, 7:39:55 AM8/22/11
to sage-s...@googlegroups.com
On 8/21/11 6:54 PM, William Stein wrote:
>
> Obvious question: are you using exactly the same versions of numpy,
> etc., in both of your tests?

Exactly. We are currently behind the latest release of matplotlib. Can
you do this in both systems?

import matplotlib
print matplotlib.__version__

and report your results? Please do the same for numpy as well.

Thanks,

Jason


Owen Densmore

unread,
Aug 25, 2011, 12:09:26 AM8/25/11
to sage-s...@googlegroups.com
@william: Obvious question: are you using exactly the same versions of numpy, etc., in both of your tests?
No they are very unlikely to be the same versions.  I used the last pre-Lion superpack_10.6_2011.07.10.sh

@jason: Exactly.  We are currently behind the latest release of matplotlib.  Can you do this in both systems?
Yes: Here are the versions:
sage: import matplotlib
sage: print matplotlib.__version__
1.0.1
sage: import numpy
sage: print numpy.__version__
1.5.1

In [1]: import matplotlib
In [2]: print matplotlib.__version__
1.1.0
In [3]: import numpy
In [4]: print numpy.__version__
2.0.0.dev-b5cdaee

All: This morning I entered a bug report (the google docs form) with more information.  I didn't see it in Trac but I don't know how these two are coordinated.  I created a small directory to repeat the bugs: http://backspaces.net/temp/plotbug.

I don't think this is a version problem due to a prior similar report: 
.. and the successful plot in the sage notebook.

Pix:
        Snapshot of truncated axes
        Snapshot of correct sagenb example
        Snapshot of non-sage, scipy stack example

Here's the report, in case the google docs had a problem.  Let me know if you would like me to download a more recent version of Sage and try again.

////
'Sage Version 4.7, Release Date: 2011-05-23' 
....
Sage Matplotlib Plots Truncate x,y axes values
....
Running the following, starting sage in the directory where the pima-indians-diabetes.data resides, creates a plot with the x & y axes numerical labels truncated.

sage: import numpy as np
sage: import matplotlib.pyplot as plt
sage: pima = np.loadtxt('pima-indians-diabetes.data',delimiter=',')
sage: indices0 = np.where(pima[:,8]==0)
sage: indices1 = np.where(pima[:,8]==1)
sage: plt.plot(pima[indices0,0],pima[indices0,1],'go');
sage: plt.plot(pima[indices1,0],pima[indices1,1],'rx');
sage: plt.show()

for the truncated labels

Note that this works correctly in sage notebooks (using savefig)
    import numpy as np
    import matplotlib.pyplot as plt
    pima = np.loadtxt(DATA+'pima-indians-diabetes.data',delimiter=',')
    indices0 = np.where(pima[:,8]==0)
    indices1 = np.where(pima[:,8]==1)
    plt.plot(pima[indices0,0],pima[indices0,1],'go');
    plt.plot(pima[indices1,0],pima[indices1,1],'rx');
    plt.savefig('pima.png')
And also works correctly in a non-sage scipy,numpy,matplotlib installation:

SagePlt.png
        Snapshot of truncated axes
SagenbPlt.png
        Snapshot of correct sagenb example
SciPyPlt.png
        Snapshot of non-sage, scipy stack example
pima-indians-diabetes.data
        Dataset

Note: these two prior posts in the support group discuss the problem:
....
The intention is to create scipy, numpy, matplotlib, ipython subset within sage so that I can work with fellow workers, having compatibility between sage & the scipy stack.

Then I'll lure them to sage!  :)
....
No backtrace, only truncated labels.

Possibly this is a back-end problem of the ipython version of sage and there is a work around?
////


Reply all
Reply to author
Forward
0 new messages