Plotly Express not importing after installation in Juypiter - python

I am trying to import plotly.express but I get the follow error:
AttributeError: module plotly.colors has no attribute named_colorscales
Code to import:
import plotly.graph_objects as go
import pandas as pd
import plotly.express as px
fig=go.Figure()
I have installed plotly express this morning using:
conda install -c plotly plotly_express
It appears to have been successfully installed without errors, but when I import it, the above error appears.
Kernel was restarted post installation.
EDIT: I have amended the code slightly as there was a slight error and an redundant import.

After a lot of work, it looks like the version of Plotly that I was using was out of date. I have upgraded that and it appears to have worked. Out of desperation, I decided to try upgrade plotly.express and it was out of date. After upgrade, worked like a charm.

Related

Why am I getting error message as "ModuleNotFoundError: No module named 'plotly.express" while it was working before?

I'm having this bizarre experience; I'm re-running a code to plot a geographical graph using Plotly and use
import plotly.express as px
but it gives me the error message saying that "ModuleNotFoundError: No module named 'plotly.express'".
I can confirm that plotly is installed, and most importantly it was working until last night.
How come its suddenly not finding the module name while it was working until last night?
Has something been changed?
Any feedback much appreciated.
Apparently, it turned out that upgrading plotly version solved the problem.
To upgrade plotly, I simply run the following codes to check the plotly version.
import plotly
plotly.__version__
That gave me the output of version of plotly as '5.11.0'. Then I upgraded the plotly version to '5.11.0' by writing the following code:
pip install plotly==5.11.0

Pie Chart in Visual Studio Code?

so my objective is to test a piechart from a code i found for visualizing stocks, kind of a portfolio. The problem is, that i always get an error. I tried using the jupyter notebook, which isnt as useful as I thougt. I am working with User Inputs. In the following are the libraries I used and the full code. Thanks in advance.
import datetime
import yfinance as yf
import plotly.graph_objects as go
https://github.com/NoamYakarOfficial/StockPortfolioVisualizer
it's working Vs code
can you check the python version or python extension install vs code,
after opening the terminal install packages
Can you run this way:
pip install yfinance
pip install plotly

Not able to save plotly plots using to_image or write_image

fig.write_image("images/fig1.png",format='png',engine='kaleido')
This makes my VSCode go bananas, the terminal hangs and the program stops then and there. Everything works fine if I remove just that line.
I want to save the plots as pngs, but it is not working. I have kaleido installed.
Try this version of kaleido.
pip install kaleido==0.1.0post1
It works for me
Complete MWE. png gets created as expected.
import plotly.graph_objects as go
import numpy as np
from pathlib import Path
f = Path.cwd().joinpath("images")
if not f.is_dir(): f.mkdir()
f = f.joinpath("fig1.png")
fig = go.Figure(go.Scatter(x=np.linspace(1,10,100), y=np.sin(np.linspace(-np.pi,np.pi, 100))))
fig.write_image(f,format='png',engine='kaleido')
versions
import plotly
import kaleido
print(plotly.__version__, kaleido.__version__)
5.5.0 0.2.1
Please follow what Gillian Grayson suggested. I am using Jupyter Notebook, Plotly version 5.13.0 and Kaleido 0.1.0.post1 and Python 3.8
Also add this to make saving figure faster
import plotly
plotly.io.kaleido.scope.mathjax= None

ImportError: no module named miniconda

I've installed miniconda on my mac following the instructions from the python website. However, when I write any new script and try and import miniconda, matplotlib or Pandas, I get the error above.
My script so far
from miniconda import *
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
CORRECTED
my code is now
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
I'm now getting the same import error for pandas and seaborn.
UPDATED:
Turns out the corrected code above works and the issue was with Python runner. The code runs when executed through the terminal. Probably an issue with permissions!
Miniconda is not a module indeed it is a variant of Anaconda python distribution, hence you could not import it. You could get further info about miniconda from the link below.
https://conda.io/miniconda.html

Import seaborn produces SHIM warning

If I try to import seaborn in my script I get this error:
/usr/local/lib/python2.7/dist-packages/IPython/html.py:14: ShimWarning:
The `IPython.html` package has been deprecated. You should import from
`notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
"`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)
I installed seaborn from pip at the last version 0.7.1 on Ubuntu 16.04 64 bit.
Anyone has ideas?
seaborn is working but this warning is very annoying.
There is an issue in the seaborn project explaining the reasons and solutions for this problem: https://github.com/mwaskom/seaborn/issues/874
Basically it says:
pip install ipywidgets
It is not an Error, it's a Warning.
To avoid Warnings from showing up you can put before importing seaborn:
import warnings
warnings.filterwarnings('ignore')
Warnings of all types won't show up anymore

Categories

Resources