I am trying to use plotly as backend in Google Colab to plot from Pandas.
import pandas as pd
!pip install plotly==4.14.1
df = pd.DataFrame(dict(a=[1,3,2], b=[3,2,1]))
df.plot(backend='plotly')
fig= df.plot()
fig.show()
When I execute the code above I get the error:
ValueError: Could not find plotting backend 'plotly'. Ensure that you've installed the package providing the 'plotly' entrypoint, or that the package has a top-level `.plot` method.
I am crearly using !pip to install plotly, So I don't know how to fix it. Any help on how to fix this is appreciated
You can try this
!pip uninstall -y -q plotly; pip install -q plotly
!pip uninstall -y -q pandas; pip install -q pandas
import pandas as pd
import plotly
pd.set_option('plotting.backend','plotly')
print(pd.__version__, plotly.__version__) # pd 1.2.5 and plotly 4.4.1
def enable_plotly_in_cell():
''' Use this function in each cell to show plot in Google Colaboratory.'''
import IPython
from plotly.offline import init_notebook_mode
display(IPython.core.display.HTML('''<script src="/static/components/requirejs/require.js"></script>'''))
init_notebook_mode(connected=False)
get_ipython().events.register('pre_run_cell', enable_plotly_in_cell)
df = pd.DataFrame({'a':[10,20,30]})
fig = df.plot()
fig.show()
Related
I'm trying to add Seaborn to my Anaconda3 python installation, and get multiple failure codes. It successfully installed using conda ... but won't import. After multiple installs/deletion/reinstalls of scipy, numpy, and seaborn, I get the following error message. I'm running Python 3.9.12, numpy 1.22.0 (downgraded from 1.23 due to prev error message stating had to be < 1.23 for Seaborn to install -- on a Windows 10. Any suggestions would be appreciated.
I can't post an image yet, so here's a summary of the error message with the failure points
code:
import Seaborn as sns
ImportError
...
import seaborn as sns
from .rcmod import * # noqa:F401, F403
from .import palettes
from . import _arpack
ImportError: DLL load failed while importing _arpack: The specified procedure could not be found.
It is not issue of seaborn. First of all uninstall numpy using this command
pip uninstall -y numpy
Then uninstall setuptools with this command
pip uninstall -y setuptools
Now, reinstall setuptools with this command
pip install setuptools
Then, You can reinstall numpy with this command
pip install numpy
Now, Your error must be solved.
I'm executing this code on KaŁgle, and install autokeras library on it,
!pip install autokeras
import matplotlib.pyplot as plt
import pandas as pd
import datetime
%matplotlib inline
#Control the default size of figures in this Jupyter notebook
%pylab inline
pylab.rcParams['figure.figsize'] = (14, 9) # Change the size of plots
#cib = pd.read_csv("../input/balmhils1/balmhils1015.csv")
# load data from csv
cib_f = pd.read_csv("../input/jkse1234/JKSE.csv") # load data from csv
f, ax = plt.subplots(figsize=(11,8))
plt.xlabel("Number of trading day")
plt.ylabel("Close price")
but I got this error.
No module named 'keras_tuner'
Upgrade the keras_tuner
!pip install keras-tuner --upgrade
I had a similar issue using PyCharm. When I installed the keras-tuner package in the Anaconda 3 prompt, I got the message that everything is already installed. The problem was, that the keras-tuner was installed in my base environment and not in the environment (virtual) which I use in PyCharm. You simply need to do the following.
check out your environments in the anaconda prompt using: conda env list
you will probably see the * on the base environment
now change to your working environment for example conda activate tf_cpu -> tf_cpu needs to be changed by your envs name (see on your list)
install your package such as pip install keras_tuner
I tried to import plotly in Anaconda with code
import plotly.graph_objs as go
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
but received error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-11-978bd9a5088a> in <module>
14
15 # import plotly.plotly as py
---> 16 import plotly.graph_objs as go
17 from plotly import __version__
18 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
ModuleNotFoundError: No module named 'plotly'
I have checked a number of similar posts to install 'plotly' on Jupyter but somehow I couldn't do it on Mac. I usually use Google Colab, could it be the reason that I am using different platforms that caused the confusion when installing?
Jupyter Notebooks start in an "environment". Anaconda created the environment and it contains a lot of useful libraries. It also holds a self-contained python interpreter. In this instance, the environment didn't have the library plotly installed (it's not a default library that Anaconda provides) so you had to install plotly in your environment that the notebook lives in.
The environments that are used with Jupyter Notebooks are a little tricky to get to in order to install things, so this way, using import sys then installing the library with !{sys.executable} -m pip install plotly finds the python interpreter with !{sys.executable} and installs plotly using pip right in the Notebook itself.
More reading:
Environments
Pip
Packages included with Anaconda
try:
import sys
!{sys.executable} -m pip install plotly
import plotly.graph_objs as go
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
I am a total newbie in Python 3 and programming in general so I looked at other peoples code and just for the beginning paste one example into Jupyter. But right at the beginning, I get an Error "ModuleNotFoundError: No module named 'xgboost'" Why does this not work?
import pandas as pd
import numpy as np
import re
import sklearn
import xgboost as xgb // error
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.tools as tls
import warnings
warnings.filterwarnings('ignore')
# Going to use these 5 base models for the stacking
from sklearn.ensemble import (RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, ExtraTreesClassifier)
from sklearn.svm import SVC
from sklearn.cross_validation import KFold
I am assuming you are running Anaconda, because this is the first error you encountered. You need to install this package: https://anaconda.org/anaconda/py-xgboost because the code you copied uses it and needs it.
You will probably get a plotly error too, so install https://anaconda.org/plotly/plotly and remember to restart Jupyter (or the kernel at least).
If you are not running Anaconda, run pip install xgboost and pip install plotly.
I tried
pip install xgboost
and
pip3 install xgboost
But it doesn't work
##ModuleNotFoundError: No module named 'xgboost'
It worked in the Jupyter Notebook cell
import sys
!{sys.executable} -m pip install xgboost
Go to command prompt >> By typing "cmd" in your windows search engine.>> Please type "pip install xgboost".
Later, close your Jupyter notebook and open it again. Run the respective cell.
If you are still getting the error then :
Add a cell in Jupyter notebook and type "pip install xgboost". Run this cell. Now it will work.
Giving a very detailed answer since beginners might be here too. Hope this helps! Be motivated! You can do it!
conda install -c conda-forge xgboost
I am relatively new to programming.
I'm trying to run the following:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'l', area_thresh=1000.0)
my_map.drawcoastlines()
my_map.drawcountries()
my_map.fillcontinents(color='red')
plt.show()
However, I get "AttributeError: 'AxesSubplot' object has no attribute 'get_axis_bgcolor'"
I'm using python 3.6, matplotlib 2.2.0, basemap 1.0.7. They were downloaded using Anaconda.
OS - Mac 10.12.4
How do I get rid of this error?
The matplotlib deprecated the get_axis_bgcolor. You'll need to update basemap to version 1.1.0 to fix this error. It's installable via conda-forge, via:
conda install -c conda-forge basemap
In case you'll get error like, "Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default." Install, the additional files via:
conda install -c conda-forge basemap-data-hires
In addition to #user45237841's answer, you can also change the resolution to c or l to resolve this error Unable to open boundary dataset file. Only the 'crude' and 'low', resolution datasets are installed by default.
my_map = Basemap(projection = 'ortho', lat_0=50, lon_0=-100,
resolution = 'c', area_thresh=1000.0)
# c is for crude and l is for low
if you are using Jupyter-notebook make sure that using --yes to processing package installing on platform. conda install -c conda-forge basemap-data-hires --yes
If you don't want to update just replace get_axis_bgcolor with get_facecolor in \site-packages\mpl_toolkits\basemap\__init__.py file.
Line 1623: fill_color = ax.get_facecolor()
Line 1767: axisbgc = ax.get_facecolor()