I'm following the tutorial plotly timeseries, here. I've also amended the code to allow for offline charts in Jupyter, here.
I'm trying to plot a timeseries in Jupyter Notebook. I get the following error.
AttributeError: module 'plotly.plotly' has no attribute 'offline'
As far as I can see I've carried out all the instructions but can't get it to work with the method they suggest.
import plotly.plotly as py
import plotly.graph_objs as go
py.offline.init_notebook_mode()
data = [go.Scatter(x=dataload.date, y=dataload.spend)]
py.offline.iplot(data)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-c9b2e8d8907c> in <module>()
2 import plotly.graph_objs as go
3
----> 4 py.offline.init_notebook_mode()
5
6 data = [go.Scatter(x=dataload.date, y=dataload.spend)]
AttributeError: module 'plotly.plotly' has no attribute 'offline'
Does anyone have a suggestion to why I might be getting this error, could it be a local setup issue?
Just use:
import plotly
plotly.offline.init_notebook_mode()
don't use: import plotly.plotly as py
You are referring different documentation. Use https://plot.ly/python/getting-started/#initialization-for-offline-plotting
Here it also provides more information regarding how to use help function.
For tutorial in offline mode: https://github.com/SayaliSonawane/Plotly_Offline_Python
Related
The error I am getting is like below:
Traceback (most recent call last)
<ipython-input-37-637818dcbe0d> in <module>
----> 1 mp = folium.map(location=[151.1780,33.7961], zoom_start=10)
2
3 choropleth = folium.Choropleth(
4 geo_data=suburbs,
5 data=rentwpostcode,
AttributeError: module 'folium' has no attribute 'map'
I tried installing folium through both conda and git clone. Both times the error remained. I also tried to removing folium.py but still it didn't work.
The error you're seeing is not related to the installation of folium. Names in Python are case-sensitive so .map() is not the same as .Map(). Change your code to mp = folium.Map(location=[151.1780,33.7961], zoom_start=10) and it'll work fine.
I have the following code:
import matplotlib.pyplot as plt
plt.cm.set_cmap("Blues")
This gives me an error:
Traceback (most recent call last):
File ".\lorenz_explorer.py", line 12, in <module>
plt.cm.set_cmap("Blues")
AttributeError: module 'matplotlib.cm' has no attribute 'set_cmap'
My matplotlib version is 3.3.1, and the function certainly exists in the documentation for 3.3.1: Link
Then am I doing something wrong or is this a bug? Do I need to import matplotlib.cm separately or something along those lines?
As the documentation link you provide shows, the name of the function is matplotlib.pyplot.set_cmap, not matplotlib.pyplot.cm.set_cmap. So you can call it with plt.set_cmap("Blues").
In other words, the function is not part of the cm library, which is somewhat counter-intuitive.
I am trying the function on this doc
import matplotlib.pyplot as plt
plt.colors()
got this error
--------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-e2c1adbcc48e> in <module>
1 import matplotlib.pyplot as plt
----> 2 plt.colors()
AttributeError: module 'matplotlib.pyplot' has no attribute 'colors'
the doc says
The colors function was deprecated in version 2.1.
without providing a substitute.
is there a substitute for matplotlib.pyplot.colors?
To be more precise here: No, there is no substitude for matplotlib.pyplot.colors because its only purpose was to allow users to get help via help(plt.colors). It was considered more harmful to confuse users by the presence of this function, which doesn't do anything, than it to be useful to let them get help on colors via pyplot. If you want to get help on colors now, you may still type
help(matplotlib.colors)
though that is a bit more lengthy.
I was following this tutorial https://www.kaggle.com/residentmario/univariate-plotting-with-pandas
and trying to do the exercise mentioned with the pokemon database but whenever I try to implement the code below I get the error mentioned below and don't understand what to do. I am using matplotlib.use('agg') because I was getting an error related to Tkinter. I am using pycharm, python 3.6 and I am on ubuntu 18.04
Here is my code:
import pandas as pd
import matplotlib
matplotlib.use('agg')
from matplotlib.pyplot import plot
df=pd.read_csv("/home/mv/PycharmProjects/visualization/pokemon.csv")
df['type1'].value_counts.plot(kind='bar')
error
Traceback (most recent call last):
File "/home/mv/PycharmProjects/visualization/univariate plotting.py",
line 9, in <module>
df['type1'].value_counts.plot(kind='bar')
AttributeError: 'function' object has no attribute 'plot'
The error states that df['type1'].value_counts is a function.
To plot the result of the function change:
df['type1'].value_counts.plot(kind='bar')
into
df['type1'].value_counts().plot(kind='bar')
I've narrowed down to this call:
fig.canvas.tostring_argb() #fig=matplotlib.pyplot.figure()
this function raises an AttributeError when I run the code as a python script.
AttributeError: 'FigureCanvasGTKAgg' object has no attribute 'renderer'
However, this code works properly if run in the ipython --pylab command line.
As far as I can tell from the documentation, the Agg renderer should work OK.
The context is that I'm trying to make a movie from figures, without saving the frames
to disk; as per this question. I'm using the approach that streams the pixel arrays
to ffmpeg (running as a separate process) to do this, I need the argb array of values from the frame.
Is there some configuration setting I can make to get matplotlib to work correctly from within a script?
Edit
Tried use('Agg') as per a comment; still fails; this is a minimal working example.
[dave#dave tools]$ python -c "import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot; fig=matplotlib.pyplot.figure(); fig.canvas.tostring_argb()"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 416, in tostring_argb
return self.renderer.tostring_argb()
AttributeError: FigureCanvasAgg instance has no attribute 'renderer'
I suspect that you have missed out the call to:
fig.canvas.draw()
before
fig.canvas.tostring_argb()
as
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
fig=matplotlib.pyplot.figure()
fig.canvas.tostring_argb()
fails for me, but
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
fig=matplotlib.pyplot.figure()
fig.canvas.draw()
fig.canvas.tostring_argb()
works.
I ended up installing and using the WXAgg backend; the Agg,and default GTKAgg, didn't work for me.