When I try to import seaborn I get the following error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/opt/conda/anaconda/lib/python3.7/site-packages/matplotlib/__init__.py in __setitem__(self, key, val)
800 try:
--> 801 cval = self.validate[key](val)
802 except ValueError as ve:
KeyError: 'axes.color_cycle'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-1-334c7a663000> in <module>
1 import matplotlib.pyplot as plt
----> 2 import seaborn as sns
3 import pandas as pd
4 import nbashots as nba # this will throw a warning if using matplotlib 1.5
5
/opt/conda/anaconda/lib/python3.7/site-packages/seaborn/__init__.py in <module>
11 from .xkcd_rgb import xkcd_rgb
12 from .crayons import crayons
---> 13 set()
14
15 __version__ = "0.6.0"
/opt/conda/anaconda/lib/python3.7/site-packages/seaborn/rcmod.py in set(context, style, palette, font, font_scale, color_codes, rc)
96 set_context(context, font_scale)
97 set_style(style, rc={"font.family": font})
---> 98 set_palette(palette, color_codes=color_codes)
99 if rc is not None:
100 mpl.rcParams.update(rc)
/opt/conda/anaconda/lib/python3.7/site-packages/seaborn/rcmod.py in set_palette(palette, n_colors, desat, color_codes)
489 """
490 colors = palettes.color_palette(palette, n_colors, desat)
--> 491 mpl.rcParams["axes.color_cycle"] = list(colors)
492 mpl.rcParams["patch.facecolor"] = colors[0]
493 if color_codes:
/opt/conda/anaconda/lib/python3.7/site-packages/matplotlib/__init__.py in __setitem__(self, key, val)
805 except KeyError:
806 raise KeyError(
--> 807 f"{key} is not a valid rc parameter (see rcParams.keys() for "
808 f"a list of valid parameters)")
809
KeyError: 'axes.color_cycle is not a valid rc parameter (see rcParams.keys() for a list of valid parameters)'
I'm pretty sure this is because I am using a more recent version of matplotlib and that color_cycle was deprecated in matplotlib 1.5. Any suggestions on how I can fix this issue? I have searched the web for hours but haven't been able to find a solution.
Related
I'm running this code to get a network figure. I'm using networkx package in python.
from pylab import rcParams
rcParams['figure.figsize'] = 14, 10
pos = nx.spring_layout(g, scale=20, k=3/np.sqrt(g.order()))
d = dict(g.degree)
plt.figure(figsize=(10, 9))
nx.draw(g, pos, node_color='green',
with_labels=True,
nodelist=d,
node_size=[d[k]*200 for k in d])
But getting the following error. This code runs fine in Kaggle or Colab but problem occurs when I try to run this segment in jupyter Notebook of my computer.
IndexError Traceback (most recent call last)
~\anaconda3\lib\site-packages\networkx\utils\decorators.py in _random_state(func, *args, **kwargs)
395 try:
--> 396 random_state_arg = args[random_state_index]
397 except TypeError as e:
IndexError: tuple index out of range
The above exception was the direct cause of the following exception:
NetworkXError Traceback (most recent call last)
<ipython-input-18-83602777a5ba> in <module>
1 from pylab import rcParams
2 rcParams['figure.figsize'] = 14, 10
----> 3 pos = nx.spring_layout(g, scale=20, k=3/np.sqrt(g.order()))
4 d = dict(g.degree)
5 plt.figure(figsize=(10, 9))
~\anaconda3\lib\site-packages\decorator.py in fun(*args, **kw)
229 if not kwsyntax:
230 args, kw = fix(args, kw, sig)
--> 231 return caller(func, *(extras + args), **kw)
232 fun.__name__ = func.__name__
233 fun.__doc__ = func.__doc__
~\anaconda3\lib\site-packages\networkx\utils\decorators.py in _random_state(func, *args, **kwargs)
398 raise nx.NetworkXError("random_state_index must be an integer") from e
399 except IndexError as e:
--> 400 raise nx.NetworkXError("random_state_index is incorrect") from e
401
402 # Create a numpy.random.RandomState instance
NetworkXError: random_state_index is incorrect
Any solution anyone?
**from geopy.geocoders import Here
exif = get_exif('earth_postcard_1599147372.jpg')
geotags = get_geotagging(exif)
coords = get_coordinates(geotags)
geocoder = Here(apikey=os.environ['API_KEY'])
print(geocoder.reverse("%s,%s" % coords))**
ERROR
KeyError Traceback (most recent call last)
<ipython-input-13-baa26ae24e59> in <module>
4 geotags = get_geotagging(exif)
5 coords = get_coordinates(geotags)
----> 6 geocoder = Here(apikey=os.environ['API_KEY'])
7 print(geocoder.reverse("%s,%s" % coords))
~\anaconda3\lib\os.py in __getitem__(self, key)
677 except KeyError:
678 # raise KeyError with the original key value
--> 679 raise KeyError(key) from None
680 return self.decodevalue(value)
681
KeyError: 'API_KEY'
Here i try to get the location of using latitude and logitude using geopy library but im getting key error
You should check whether you have set your environment parameter.You can enter into python command line mode then input :
import os
os.environ.keys()
System will output all the environment parameter."API_KEY" should not be set. If you set this key in system parameter list,this error will be gone.
This is my python code. It's objective is to take in two images from the file system then produce plots based on the analysis of the images.
I installed the Anaconda package and I'm working in iPython on Windows 10 (Python 2.7).
When I run my code I get: AttributeError: 'NoneType' object has no attribute 'is_interactive'
I ensured that the folders with my images exist in the file system.
# Bring in necessary libraries
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from skimage import color
import skimage.filters as filters
from skimage.transform import hough_circle
from skimage.feature import peak_local_max
from skimage import feature
from skimage import morphology
from skimage.draw import circle_perimeter
from skimage import img_as_float, img_as_ubyte
from skimage import segmentation as seg
from skimage.morphology import watershed
from scipy import ndimage as nd
from scipy.ndimage import convolve
from skimage import feature
import glob # for bulk file import
# Set defaults
plt.rcParams['image.cmap'] = 'gray' # Display grayscale images in... grayscale.
plt.rcParams['image.interpolation'] = 'none' # Use nearest-neighbour
plt.rcParams['figure.figsize'] = 10, 10
# Import test images
imgpaths = glob.glob("C:\\images\\ * .jpg") + glob.glob("C:\\images\\ * .png")
imgset = [img_as_ubyte(mpimg.imread(x)) for x in imgpaths]
# Display thumbnails of the images to ensure loading
plt.figure()
for i,img in enumerate(imgset):
plt.subplot(1, len(imgset), i+1)
plt.imshow(img, cmap = 'gray')
# Plots a histogram of the image, splitting into individual channels if necessary.
def plot_multichannel_histo(img):
if img.ndim == 2: # plot grayscale histo
plt.hist(img.flatten(), 256, range=(0,255), color='k', histtype='step')
elif img.ndim == 3: # print rgb histo
plt.hist(img.reshape(-1,3), 256, range=(0,255), color=['r','g','b'],histtype='step')
else: # Not an image
print("Must pass a valid RGB or grayscale image")
plt.xlim([0,255])
# Apply to test images
for i,img in enumerate(imgset):
plt.figure()
plt.subplot(1, 2, 1)
plt.imshow(img, cmap='gray')
plt.subplot(1, 2, 2)
plot_multichannel_histo(img)
iPython spits this out:
---------------------------------------------------------------------------
UnknownBackend Traceback (most recent call last)
<ipython-input-1-bcf46d40fe9f> in <module>()
1 # Bring in necessary libraries
----> 2 get_ipython().magic(u'matplotlib inline')
3 import matplotlib.pyplot as plt
4 import matplotlib.image as mpimg
5 import numpy as np
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, arg_s)
2156 magic_name, _, magic_arg_s = arg_s.partition(' ')
2157 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158 return self.run_line_magic(magic_name, magic_arg_s)
2159
2160 #-------------------------------------------------------------------------
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\core\interactiveshell.pyc in run_line_magic(self, magic_name, line)
2077 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2078 with self.builtin_trap:
-> 2079 result = fn(*args,**kwargs)
2080 return result
2081
<decorator-gen-105> in matplotlib(self, line)
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k)
186 # but it's overkill for just that one bit of state.
187 def magic_deco(arg):
--> 188 call = lambda f, *a, **k: f(*a, **k)
189
190 if callable(arg):
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\core\magics\pylab.pyc in matplotlib(self, line)
98 print("Available matplotlib backends: %s" % backends_list)
99 else:
--> 100 gui, backend = self.shell.enable_matplotlib(args.gui)
101 self._show_matplotlib_backend(args.gui, backend)
102
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\core\interactiveshell.pyc in enable_matplotlib(self, gui)
2945 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
2946
-> 2947 pt.activate_matplotlib(backend)
2948 pt.configure_inline_support(self, backend)
2949
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\core\pylabtools.pyc in activate_matplotlib(backend)
292 matplotlib.rcParams['backend'] = backend
293
--> 294 import matplotlib.pyplot
295 matplotlib.pyplot.switch_backend(backend)
296
C:\Users\Peter\Anaconda2\lib\site-packages\matplotlib\pyplot.py in <module>()
2533 # are no-ops and the registered function respect `mpl.is_interactive()`
2534 # to determine if they should trigger a draw.
-> 2535 install_repl_displayhook()
2536
2537 ################# REMAINING CONTENT GENERATED BY boilerplate.py ##############
C:\Users\Peter\Anaconda2\lib\site-packages\matplotlib\pyplot.py in install_repl_displayhook()
164 ipython_gui_name = backend2gui.get(get_backend())
165 if ipython_gui_name:
--> 166 ip.enable_gui(ipython_gui_name)
167 else:
168 _INSTALL_FIG_OBSERVER = True
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\terminal\interactiveshell.pyc in enable_gui(self, gui)
450 def enable_gui(self, gui=None):
451 if gui:
--> 452 self._inputhook = get_inputhook_func(gui)
453 else:
454 self._inputhook = None
C:\Users\Peter\Anaconda2\lib\site-packages\IPython\terminal\pt_inputhooks\__init__.pyc in get_inputhook_func(gui)
36
37 if gui not in backends:
---> 38 raise UnknownBackend(gui)
39
40 if gui in aliases:
UnknownBackend: No event loop integration for 'inline'. Supported event loops are: qt, qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx
Error in callback <function post_execute at 0x0000000006E06908> (for post_execute):
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\Peter\Anaconda2\lib\site-packages\matplotlib\pyplot.py in post_execute()
146
147 def post_execute():
--> 148 if matplotlib.is_interactive():
149 draw_all()
150
AttributeError: 'NoneType' object has no attribute 'is_interactive'
Error in callback <function post_execute at 0x0000000006E06908> (for post_execute):
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\Peter\Anaconda2\lib\site-packages\matplotlib\pyplot.py in post_execute()
146
147 def post_execute():
--> 148 if matplotlib.is_interactive():
149 draw_all()
150
AttributeError: 'NoneType' object has no attribute 'is_interactive'
The current analytical workspace code seems to have some import error.
I tried this ..
from cubes import Workspace
workspace = Workspace(config="slicer.ini")
workspace.import_model("model.json")
workspace.list_cubes()
And I get this error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-f80f0974af47> in <module>()
----> 1 workspace.list_cubes()
/home/anand/.virtualenvs/cubes/local/lib/python2.7/site-packages/cubes/workspace.pyc in list_cubes(self, identity)
535 """
536
--> 537 all_cubes = self.namespace.list_cubes(recursive=True)
538
539 if self.authorizer:
/home/anand/.virtualenvs/cubes/local/lib/python2.7/site-packages/cubes/namespace.pyc in list_cubes(self, recursive)
112 name = cube["name"]
113 if name in cube_names:
--> 114 raise ModelError("Duplicate cube '%s'" % name)
115 cube_names.add(name)
116
NameError: global name 'ModelError' is not defined
I'm using the 1.0.1 version.
And have tried the latest master from github, but that fails even at the
from cubes import Workspace
Setup: Using Python 3.4.1 from the Anaconda 2.1.0 64-bit installer for Windows 8.1
Using IPython 2.2.0 console
As usual with the Anaconda installer, I have matplotlib 1.4.0 that comes with it.
And I updated from the default sympy on Anaconda to sympy 0.7.6
Problem: I am trying to plot geometric entities as discussed in the sympy documentation http://docs.sympy.org/latest/modules/plotting.html#plot-geom in at least three ways, all yielding errors.
First try using the 'older' PygletPlot, the module being used in the above reference documentation:
In [1]: from sympy.plotting.pygletplot import PygletPlot as Plot
In [2]: from sympy import Point, Circle
In [3]: c1 = Circle(Point(1, 0), 3)
In [4]: p = Plot(axes='label_axes=True')
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-34da7d3c112c> in <module>()
----> 1 p = Plot(axes='label_axes=True')
C:\Anaconda3\lib\site-packages\sympy\plotting\pygletplot\__init__.py in PygletPlot(*args, **kwargs)
137 """
138
--> 139 import plot
140 return plot.PygletPlot(*args, **kwargs)
141
ImportError: No module named 'plot'
In [5]: Plot(c1)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-4edba1117b3a> in <module>()
----> 1 Plot(c1)
C:\Anaconda3\lib\site-packages\sympy\plotting\pygletplot\__init__.py in PygletPlot(*args, **kwargs)
137 """
138
--> 139 import plot
140 return plot.PygletPlot(*args, **kwargs)
141
ImportError: No module named 'plot'
In [6]: p = Plot()
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-f2ff2ed54331> in <module>()
----> 1 p = Plot()
C:\Anaconda3\lib\site-packages\sympy\plotting\pygletplot\__init__.py in PygletPlot(*args, **kwargs)
137 """
138
--> 139 import plot
140 return plot.PygletPlot(*args, **kwargs)
141
ImportError: No module named 'plot'
Second try using the 'newer' plotting module, which keeps being recommended in answers for most plotting problems with sympy:
In [1]: from sympy.plotting.plot import Plot
In [2]: from sympy import Point, Circle
In [3]: c1 = Circle(Point(1, 0), 3)
In [4]: p = Plot(c1)
In [5]: p.show()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-709f73884a30> in <module>()
----> 1 p.show()
C:\Anaconda3\lib\site-packages\sympy\plotting\plot.py in show(self)
182 if hasattr(self, '_backend'):
183 self._backend.close()
--> 184 self._backend = self.backend(self)
185 self._backend.show()
186
C:\Anaconda3\lib\site-packages\sympy\plotting\plot.py in __new__(cls, parent)
1054 matplotlib = import_module('matplotlib', min_module_version='1.1.0', catch=(RuntimeError,))
1055 if matplotlib:
-> 1056 return MatplotlibBackend(parent)
1057 else:
1058 return TextBackend(parent)
C:\Anaconda3\lib\site-packages\sympy\plotting\plot.py in __init__(self, parent)
861 def __init__(self, parent):
862 super(MatplotlibBackend, self).__init__(parent)
--> 863 are_3D = [s.is_3D for s in self.parent._series]
864 self.matplotlib = import_module('matplotlib',
865 __import__kwargs={'fromlist': ['pyplot', 'cm', 'collections']},
C:\Anaconda3\lib\site-packages\sympy\plotting\plot.py in <listcomp>(.0)
861 def __init__(self, parent):
862 super(MatplotlibBackend, self).__init__(parent)
--> 863 are_3D = [s.is_3D for s in self.parent._series]
864 self.matplotlib = import_module('matplotlib',
865 __import__kwargs={'fromlist': ['pyplot', 'cm', 'collections']},
AttributeError: 'Circle' object has no attribute 'is_3D'
In [6]: Plot(c1)
Out[6]: <sympy.plotting.plot.Plot at 0x6f74ac8>
Third try using the plot() function which the sympy documentation recommends for interactive work:
In [1]: from sympy import plot
In [2]: from sympy import Point, Circle
In [3]: c1 = Circle(Point(1, 0), 3)
In [4]: plot(c1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-685b4d90c5ac> in <module>()
----> 1 plot(c1)
C:\Anaconda3\lib\site-packages\sympy\plotting\plot.py in plot(*args, **kwargs)
1274 series = []
1275 plot_expr = check_arguments(args, 1, 1)
-> 1276 series = [LineOver1DRangeSeries(*arg, **kwargs) for arg in plot_expr]
1277
1278 plots = Plot(*series, **kwargs)
TypeError: 'NoneType' object is not iterable
Thanks for your attention. This is my first time writing a question so I hope I have provided enough information.