【问题标题】:Unexpected exception formatting exception. Falling back to standard exception in Python意外异常格式化异常。回到 Python 中的标准异常
【发布时间】:2023-02-14 18:43:33
【问题描述】:

我想用cartopy做EDA的数据图。但结果显示 Unexpected exception formatting exception。使用图表回退到标准异常

这是我的代码

# Understanding this code is not essential for the tutorial 

import cartopy.crs as ccrs
import cartopy.feature as cfeature

# Latitude and longitude for the edges of the map
lat1, lat2, lon1, lon2= 32, 42.5, -125, -114

# Create figures
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(1, 1, 1, projection = ccrs.Mercator())

# Get latitude and longitude for each data point
x, y = (train['Longitude'].to_numpy(), train['Latitude'].to_numpy())

# Scatter plot as heat map
ax.scatter(x,y,s=(train['Population'].to_numpy()/30.0), c=train['MedianHouseValue'].to_numpy(), 
           edgecolors='none', cmap=plt.get_cmap('rainbow'), alpha=0.5, transform=ccrs.PlateCarree())

# Add state borders and coast line
ax.add_feature(cfeature.STATES.with_scale('50m'))
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
ax.set_extent([-125, -113.5, 32, 42.5], crs=ccrs.PlateCarree())

ax.set_title('Median house values in California (training data)', fontsize=17, y=1.01, fontweight='bold')

plt.show()

【问题讨论】:

  • 欢迎来到堆栈溢出!当询问错误时,请始终包括 full traceback - 它包含我们(和您)需要能够识别触发异常的位置的有价值的调试信息。

标签: python cartopy


【解决方案1】:

有什么解决办法吗。我遇到了同样的错误:

    Traceback (most recent call last):   File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreormatters.py", line 222, in catch_format_error
        except NotImplementedError:   File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreormatters.py", line 339, in __call__
        # Finally look for special method names   File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncorepylabtools.py", line 151, in print_figure   File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesmatplotlibackend_bases.py", line 2289, in print_figure
        cbook._setattr_cm(self.figure.canvas, _device_pixel_ratio=1),    File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesmatplotlibackend_bases.py", line 1544, in _get_renderer
        # Figure.draw() by raising an exception.   File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesmatplotlib_apideprecation.py", line 390, in wrapper
        f"support for them will be removed %(removal)s.")   File "c:UserskocthoAnaconda3envspy3.10condalibinspect.py", line 3185, in bind
        return self._bind(args, kwargs)   File "c:UserskocthoAnaconda3envspy3.10condalibinspect.py", line 3174, in _bind
        raise TypeError( TypeError: got an unexpected keyword argument 'orientation'
    
    During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreinteractiveshell.py", line 1997, in showtraceback
    sys.last_traceback = tb
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreultratb.py", line 1112, in structured_traceback
    etype, value, tb = sys.exc_info()
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreultratb.py", line 1006, in structured_traceback
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreultratb.py", line 859, in structured_traceback
    evalue: Optional[BaseException],
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreultratb.py", line 812, in format_exception_as_a_whole
    ColorsNormal = Colors.Normal  # used a lot
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesIPythoncoreultratb.py", line 730, in format_record
    )
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesstack_datautils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesstack_datacore.py", line 734, in lines
    line.leading_indent = leading_indent
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesstack_datautils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesstack_datacore.py", line 681, in included_pieces
    return min(indents) if indents else 0
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesstack_datautils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesstack_datacore.py", line 660, in executing_piece
    pieces.insert(0, scope_pieces[0])
  File "c:UserskocthoAnaconda3envspy3.10condalibsite-packagesexecutingexecuting.py", line 168, in only
executing.executing.NotOneValueFound: Expected one value, found 0

代码在更新 conda 后运行...我收到错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-04
    • 2022-08-13
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多