joferkington / mplstereonet

Stereonets for matplotlib
MIT License
189 stars 66 forks source link

Spot an error of mplstereonet while using Google Colab #34

Closed yohanesnuwara closed 4 years ago

yohanesnuwara commented 4 years ago

Hi @joferkington, I just tried the code of basic usage in Google Colab 2 weeks ago and it succeeded, but when I re-try to plot in Google Colab again, I spot an error that I couldn't solve. It's related to code: ax = fig.add_subplot(111, projection='stereonet'). The error is as follows:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-5f249805830b> in <module>()
      3 
      4 fig = plt.figure()
----> 5 ax = fig.add_subplot(111, projection='stereonet')
      6 
      7 strike, dip = 315, 30

11 frames
/usr/local/lib/python3.6/dist-packages/mplstereonet/stereonet_transforms.py in transform_non_affine(self, ll)
     69     _inverse_type = 'BaseInvertedTransform'
     70     def transform_non_affine(self, ll):
---> 71         longitude = ll[:, 0:1]
     72         latitude  = ll[:, 1:2]
     73         clong = self._center_longitude

TypeError: tuple indices must be integers or slices, not tuple

I also attached my Colab notebook to you, link here. Is there something wrong or missing in my codes? Looking forward for your help :)

fwrite commented 4 years ago

Probably ll is expected to be a numpy.ndarray, but is a tuple instead. You might be able to trace back ll. As a quick fix you can cast it to an array (just like #20) locally? There has probably been some change in the API that remained unnoticed.

yohanesnuwara commented 4 years ago

@fwrite thanks! I have found the issue of running mplstereonet in Google Colab using Python 3 runtime. I found mplstereonet working in Python 2 runtime instead.

robgeotech commented 4 years ago

@yohanesnuwara I had the same issue in Jupyter notebook (with Anacondo) after updating versions of Matplotlib (from 3.1.1 to 3.1.2) and Numpy. Updating to the development version of mplstereonet as referenced in another issue (https://github.com/joferkington/mplstereonet/issues/16#issuecomment-275771610) seemed to solve the problem.

ICWallis commented 4 years ago

I had the same issue in VSCode and Juypter Lab (using Anaconda managed environments) also resolved by updating to the development version as linked above #16 . Thanks joferkington for making and updating this tool. It's been a great help to my doctoral research.

/opt/anaconda3/envs/Py36/lib/python3.6/site-packages/mplstereonet/stereonet_transforms.py in transform_non_affine(self, ll) 69 _inverse_type = 'BaseInvertedTransform' 70 def transform_non_affine(self, ll): ---> 71 longitude = ll[:, 0:1] 72 latitude = ll[:, 1:2] 73 clong = self._center_longitude

TypeError: tuple indices must be integers or slices, not tuple

joferkington commented 4 years ago

As other folks mentioned, this has been fixed in master for quite awhile, but things were long overdue for a release. v0.6 includes fixes for this, among other things, so a default pip install should work now. To upgrade to the current release, you can do either pip install 'mplstereonet==0.6.0' or pip install --upgrade mplstereonet