Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib inline problem #15

Open
freedom00y opened this issue Dec 5, 2019 · 3 comments
Open

matplotlib inline problem #15

freedom00y opened this issue Dec 5, 2019 · 3 comments

Comments

@freedom00y
Copy link

I tried to use the pychimera in the notebook. I tried to plot something inline using the command “%matplotlib inline”.
When I run some code related with plots in “pychimera notebook”, it will show errors. But when I run the same code in “jupiter notebook”, it run successfully.
I’d like to know how to solve this problem.

Here is my code and error message:

Code

from pychimera import enable_chimera, enable_chimera_inline, chimera_view
enable_chimera()
enable_chimera_inline()
import chimera
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

a = np.arange(10)
plt.hist(a)
plt.show()

Error message


AttributeError Traceback (most recent call last)
in ()
10 a = np.arange(10)
11 plt.hist(a)
---> 12 plt.show()

/Users/zhouhuiya/anaconda3/envs/pychimera/lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyc in show(close, block)
37 display(
38 figure_manager.canvas.figure,
---> 39 metadata=_fetch_figure_metadata(figure_manager.canvas.figure)
40 )
41 finally:

/Users/zhouhuiya/anaconda3/envs/pychimera/lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyc in _fetch_figure_metadata(fig)
172 """Get some metadata to help with displaying a figure."""
173 # determine if a background is needed for legibility
--> 174 if _is_transparent(fig.get_facecolor()):
175 # the background is transparent
176 ticksLight = _is_light([label.get_color()

/Users/zhouhuiya/anaconda3/envs/pychimera/lib/python2.7/site-packages/ipykernel/pylab/backend_inline.pyc in _is_transparent(color)
193 def _is_transparent(color):
194 """Determine transparency from alpha."""
--> 195 rgba = colors.to_rgba(color)
196 return rgba[3] < .5

AttributeError: 'module' object has no attribute 'to_rgba'

Here is my conda list:

Name Version Build Channel

appnope 0.1.0 py27hb466136_0
attrs 19.1.0 py27_1
backports 1.0 py_2
backports.functools_lru_cache 1.5 py_2
backports.shutil_get_terminal_size 1.0.0 py27_2
backports_abc 0.5 py27h6972548_0
blas 1.0 openblas
bleach 3.1.0 py27_0
certifi 2019.11.28 py27_0
configparser 3.7.4 py27_0
cycler 0.10.0 py27hfc73c78_0
dbus 1.13.6 h90a0687_0
decorator 4.4.0 py27_1
defusedxml 0.6.0 py_0
entrypoints 0.3 py27_0
enum34 1.1.6 py27_1
expat 2.2.6 h0a44026_0
freetype 2.9.1 hb4e5f40_0
functools32 3.2.3.2 py27_1
futures 3.3.0 py27_0
gettext 0.19.8.1 h15daf44_3
glib 2.56.2 hd9629dc_0
icu 58.2 h4b95b61_1
ipaddress 1.0.22 py27_0
ipykernel 4.10.0 py27_0
ipython 5.8.0 py27_0
ipython_genutils 0.2.0 py27h8b9a179_0
ipywidgets 7.5.1 py_0
jinja2 2.10.1 py27_0
jpeg 9b he5867d9_2
jsonschema 3.0.2 py27_0
jupyter 1.0.0 py27_7
jupyter_client 5.3.1 py_0
jupyter_console 5.2.0 py27_1
jupyter_core 4.5.0 py_0
kiwisolver 1.1.0 py27h0a44026_0
libcxx 4.0.1 hcfea43d_1
libcxxabi 4.0.1 hcfea43d_1
libedit 3.1.20181209 hb402a30_0
libffi 3.2.1 h475c297_4
libgfortran 3.0.1 h93005f0_2
libiconv 1.15 hdd342a3_7
libopenblas 0.3.6 hdc02c5d_1
libpng 1.6.37 ha441bb4_0
libsodium 1.0.16 h3efe00b_0
markupsafe 1.1.1 py27h1de35cc_0
matplotlib 2.2.4 pypi_0 pypi
mistune 0.8.4 py27h1de35cc_0
nbconvert 5.5.0 py_0
nbformat 4.4.0 py27hddc86d0_0
ncurses 6.1 h0a44026_1
nglview 1.1.7 py_0 bioconda
nomkl 3.0 0
notebook 5.7.8 py27_0
numpy 1.16.4 py27h926163e_0
numpy-base 1.16.4 py27ha711998_0
pandoc 2.2.3.2 0
pandocfilters 1.4.2 py27_1
pathlib2 2.3.4 py27_0
pcre 8.43 h0a44026_0
pexpect 4.7.0 py27_0
pickleshare 0.7.5 py27_0
pip 19.2.2 py27_0
prometheus_client 0.7.1 py_0
prompt_toolkit 1.0.15 py27h4a7b9c2_0
ptyprocess 0.6.0 py27_0
pychimera 0.2.7 py27_0 insilichem
pygments 2.4.2 py_0
pyparsing 2.4.2 py_0
pyqt 5.9.2 py27h655552a_2
pyrsistent 0.14.11 py27h1de35cc_0
python 2.7.16 h97142e2_4
python-dateutil 2.8.0 py27_0
pytz 2019.2 py_0
pyzmq 18.1.0 py27h0a44026_0
qt 5.9.7 h468cd18_1
qtconsole 4.5.3 py_0
readline 7.0 h1de35cc_5
scandir 1.10.0 py27h1de35cc_0
send2trash 1.5.0 py27_0
setuptools 41.0.1 py27_0
simplegeneric 0.8.1 py27_2
singledispatch 3.4.0.3 py27he22c18d_0
sip 4.19.8 py27h0a44026_0
six 1.12.0 py27_0
sqlite 3.29.0 ha441bb4_0
subprocess32 3.5.4 py27h1de35cc_0
terminado 0.8.2 py27_0
testpath 0.4.2 py27_0
tk 8.6.8 ha441bb4_0
tornado 5.1.1 py27h1de35cc_0
traitlets 4.3.2 py27hcf08151_0
wcwidth 0.1.7 py27h817c265_0
webencodings 0.5.1 py27_1
wheel 0.33.4 py27_0
widgetsnbextension 3.5.1 py27_0
zeromq 4.3.1 h0a44026_3
zlib 1.2.11 h1de35cc_3

Python version:
Python 2.7.16 :: Anaconda, Inc.

@jaimergp
Copy link
Member

jaimergp commented Dec 5, 2019

I suspect this has to do with the version of matplotlib Chimera itself ships, which will get loaded before the one in your conda env.

This is not an easy problem to solve, but the quickest (and dirtiest) way to do it is to remove matplotlib from UCSF Chimera. Since this will affect the extension inside Chimera, I would recommend having a separate installation (maybe the headless one?) that you can modify without fear. You can point to that separate installation for pychimera using the CHIMERADIR environment variable.

To uninstall libraries already present in Chimera, you need to install pip first in Chimera, and then use that one to remove whatever you need. Let me know if you need help in this step.

@freedom00y
Copy link
Author

So can I use the matplotlib package in Chimera?

@jaimergp
Copy link
Member

jaimergp commented Dec 9, 2019

In principle, yes. Try to follow the instructions above and let me know if it works for you!

A second alternative would be:

  1. Use pychimera notebook to generate all the numeric data you want to plot, but do not import matplotlib yet. Save the data to disk (via pickle, numpy.save, pandas.Dataframe.to_csv, etc). Get rid of all chimera objects so you can use the data without pychimera!
  2. In a separate instance, run jupyter notebook and load the data. You will be able to plot it with matplotlib just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants