Why Plotly is not working on Jupyter Lab? - python

I had to update my Macbook Air's iOS (Catalina), since I updated to this iOS's version, plotly stop working on my Jupyter-lab's enviroment.
I already followed the Getting Started's steps showed on plotly website:
$ pip install jupyterlab==1.2 "ipywidgets>=7.5"
When I run a random example, it shows an empty white block:
The libraries that I was importing (The ones that worked before):
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import cufflinks as cf
from plotly.offline import download_plotlyjs,init_notebook_mode, plot,iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)
cf.go_offline()
%matplotlib inline

You need to have the relevant JupyterLab extensions installed, as per our Getting Started guide here: https://plot.ly/python/getting-started/
If you're having trouble, here is our troubleshooting guide: https://plot.ly/python/troubleshooting/

Related

name 'netCDF4' is not defined - python in RStudio

I have recently taken up working on Python 3.6 implemented in RStudio using Miniconda and the library reticulate.
I have installed all the packages that I need using
reticulate::py_install('name of the packages')
when I try to import some .nc data as follow:
import numpy as np
import pandas as pd
import cartopy as cp
from cartopy import crs as ccrs, feature as cfeature
import matplotlib.pyplot as plt
import xarray as xr
import openpyxl
import netCDF4
#%%
adt = xr.open_dataset("G:/Research/ADT.nc")
I get this error:
NameError: name 'netCDF4' is not defined
I have looked at possible solutions, like:
netCDF4 import not being found by Python
but I have installed the package netCDF4 and xarray as the other ones, which do not give any issue (so far)
I had this error in Jupiter Notebook, but then I restarted the Kernel and ran again, and it was fine. I installed netcdf4 using conda.

how to show boxplot in jupyter?

I have problem with showing below plot
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set_theme(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x=tips["total_bill"])`enter code here`
The error is: module 'seaborn' has no attribute 'set_theme'
What should I do?
I got the same problem, then I read the release note of v0.11.0 (September 2020) https://seaborn.pydata.org/whatsnew.html
Theming
API The set() function has been renamed to set_theme() for more clarity about what it does. For the foreseeable future, set() will remain as an alias, but it is recommended to update your code.
So I uninstall and reinstall the seaborn, now it works :)
pip uninstall seaborn
pip install seaborn

cannot plot with matplotlib and pandas

I am using OSX (Mojave 10.14.3) and am having a strange issue plotting a pandas (0.24.2) dataframe using matplotlib (3.0.3). I am using python 3.7.3.
So, the code is as:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
'name':['john','mary','peter','jeff','bill','lisa','jose'],
'age':[23,78,22,19,45,33,20],
'gender':['M','F','M','M','M','F','M'],
'state':['california','dc','california','dc','california','texas','texas'],
'num_children':[2,0,0,3,2,1,4],
'num_pets':[5,1,0,5,2,2,3]
})
df.plot(kind='scatter',x='num_children',y='num_pets',color='red')
plt.show()
All this does is show an empty window with nothing in it. I was expecting a scatterplot with 7 points. The example is taken from the web tutorial as is.
EDIT
plt.savefig('myfilename.png')
Savefig works.
I am not sure if this will help anyone but I basically had to install python as a framework to make it work. I was using Anaconda, so something like:
conda install python.app
pythonw script.py # note using pythonw
I, then, was able to get the plot to render correctly by using the macosx backend:
import matplotlib as mpl
mpl.use('MacOSX')

PyViz: Having trouble displaying visualizations side by side

I'm following the PyViz tutorial found here: http://pyviz.org/tutorial/01_Workflow_Introduction.html, and I am running into an issue with displaying images side by side when using the exact code from the tutorial (in the New York vs Texas Measles example).
I should mention that I did not download the conda environment as outlined in the tutorial. I opened a new Jupyter Notebook, installed all the specified libraries(I hope), and downloaded the examples from the PyViz github page.
The libraries I downloaded/imported are the following:
import holoviews as hv
import bokeh
import matplotlib
import pandas as pd
import datashader
import dask
import geoviews
import numpy as np
import hvplot.pandas
import hvplot
import holoviews as hv
hv.extension('bokeh', 'matplotlib', width="100")
The part of the tutorial code that does not work is the following:
by_state["Texas"].relabel('Texas') + by_state["Florida"].relabel('Florida')
Both statements run on their own, but the plus sign does not appear to work. The error states:
TypeError: gridplot() got an unexpected keyword argument 'width'
The rest of the tutorial runs smoothly. Does anyone have any insight into what could be going wrong here?
Thank you!

python syntax error in matplotlib

I am using python 3.5, pycharm and getting invalid syntax at %matplotlib inline as output here is my code:
import time
import requests
import cv2
import operator
import numpy as np
# Import library to display results
import matplotlib.pyplot as plt
%matplotlib inline
I think this link may be what you are looking for: How to make IPython notebook matplotlib plot inline
Put the %matplotlib inline on the first line. This is useful in the context of using Jupyter notebooks (http://jupyter.readthedocs.io/en/latest/)

Categories