Skip to content

Error when reading file after importing pyplot in IPython/Jupyter #18

@parnalte

Description

@parnalte

Hi,

First of all, thanks a lot for the code! :)

I'm getting a strange error when trying to read a polygon file from the IPython console. I can read a file without problems initially but, if I first import matplotlib.pyplot and try to read a polygon file afterwards, I get an OSError. Here's a transcript:

(base) pablo@mimas:$ ipython
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pymangle                                                                                               

In [2]: m = pymangle.Mangle("basic_rect_mask.ply")                                                                    

In [3]: m                                                                                                             
Out[3]: 
Mangle
	file:       basic_rect_mask.ply
	area:       2.26946 sqdeg
	npoly:      1
	pixeltype:  'u'
	pixelres:   -1
	real:       10
	npix:       0
	snapped:    0
	balkanized: 0
	weightfile: 
	verbose:    0

In [4]: m.area                                                                                                        
Out[4]: 2.2694632669506295698

In [5]: import matplotlib.pyplot as plt                                                                               

In [6]: m2 = pymangle.Mangle("basic_rect_mask.ply")                                                                   
Failed to read cap
failed to read polygon 0
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-6-5ca19ad5eaa4> in <module>
----> 1 m2 = pymangle.Mangle("basic_rect_mask.ply")

~/anaconda3/lib/python3.7/site-packages/pymangle/mangle.py in __init__(self, filename, verbose)
     56         else:
     57             verb=0
---> 58         super(Mangle,self).__init__(filename,verb)
     59 
     60     def read_weights(self, weightfile):

OSError: Error reading mangle mask basic_rect_mask.ply

In [7]: !cat basic_rect_mask.ply                                                                                      
1 polygons
polygon 0 ( 4 caps, 1 weight, 0 pixel, 0.000691318044679215 str):
 0.5372996083468238328 -0.8433914458128857007 0.0000000000000000005 1
 0.6552660971010802629 0.4378348082356948762 0.6155704855555779053 1
 -0.5735764363510460959 0.8191520442889917898 0.0000000000000000005 1
 -0.6684388292532475694 -0.4466365464628057830 -0.5947313064824531940 1

Some things I've tried:

  • I tried several different polygon files with the same result
  • If I only import matplotlib I don't get the error
  • I get the same error when trying to read a polygon file after using the %matplotlib magic command in IPython
  • If I run the same code directly in a Python console, I don't get the error, and the file is read fine
  • Strangely, in a Jupyter Notebook, I get the same error after calling the %matplotlib magic command, but not after just importing matplotlib.pyplot

Relevant versions (from Anaconda):

  • Python: 3.7.3
  • IPython: 7.8.0
  • Notebook: 6.0.1
  • Matplotlib: 3.1.1
  • Pymangle: 0.9.1

Of course, it is easy to work around this issue (just read your files before importing pyplot) but I'm curious whether there is a fix for it.

Cheers,
Pablo.

PS. Sorry I hit 'Enter' too early when starting to write!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions