python - 在 Jupyter Notebboks 中保存绘图时出现驱动错误
问题描述
我正在尝试从 Ipython 笔记本中保存文件。我正在使用该geopandas
库来创建我的情节。但是我已经在 jupyter 的树中创建了目录。
import os
import geopandas as gpd
from matplotlib import pyplot as plt
import matplotlib as mpl
%matplotlib inline
%matplotlib notebook
MAP_DIR_PATH = os.path.join('maps')
MAP_USA_FILE_PATH = os.path.join(MAP_DIR_PATH, 'USA')
PLOT_DIR_PATH = os.path.join('plots')
PLOT_USA_FILE_PATH = os.path.join(PLOT_DIR_PATH, 'risk_USA_states_top.png')
CMAP = 'YlGnBu'
def plot_settings(fig,ax,zlabel,colormap,norm):
fig.set_size_inches(12,12)
plt.xlim(-2.2e6,2.5e6)
plt.ylim(-2.2e6,1e6)
plt.xticks([])
plt.yticks([])
plt.axis('off')
#Colorbar
fig = ax.get_figure()
cax = fig.add_axes([0.92, 0.27, 0.025, 0.5])
sm = plt.cm.ScalarMappable(cmap=colormap, norm=norm)
sm._A = []
fig.colorbar(sm, cax=cax)
cax.set_ylabel(zlabel,fontsize=20)
plt.tick_params(axis='both', which='major', labelsize=15)
# Plot
gdf_plot = gpd.read_file(MAP_USA_FILE_PATH)
fig, ax = plt.subplots()
column = 'IRI'
norm = mpl.colors.Normalize(vmin=0, vmax=1)
gdf_plot.plot(ax=ax, column=column, cmap=CMAP, norm=norm, lw=0, vmin=0, vmax=1)
plot_settings(fig, ax, 'Infodemic Risk Index', CMAP, norm)
# Save figure
plt.savefig(PLOT_USA_FILE_PATH,
bbox_inches = 'tight',
definition = 'high',
transparent=True)
DriverError: 'maps/USA' not recognized as a supported file format.
解决方案
推荐阅读
- python - 如何在 for 和 if 循环中格式化 Python 列表?
- python - 如何将我的 emailpass[0] 和 emailpass[1] 放在 request.get url 上?
- java - 如何生成随机实数列表
- html - 使用 svg dashoffset/dasharray 按 360 度的百分比绘制一个圆
- jquery - 根据纯文本数字打开/关闭复选框
- python - Python在嵌套字典中搜索键/值
- r - 如何使用 R 中的列表条目有效地设置矩阵的值?
- c++ - 如何处理已经存在的密钥的插入?
- vba - MS Access 仅在更改特定方法时停止工作
- docker - 无法为旧版本(标签)的 postgres 找到 dockerfile