fig=plt.figure(figsize=(11,8.5)) ax=fig.add_subplot(1,1,1, projection=ccrs.Mollweide()) h=ax.contourf(lon,lat,dat, levels=list(range(0,6,1)), extend='both', cmap='coolwarm', transform=ccrs.Mollweide()) c=ax.contour(lon,lat,dat, levels=list(range(0,6,2)), colors='k',linewidths=1, transform=ccrs.Mollweide()) ax.coastlines()然后怎么把海洋填成灰色
时间: 2023-06-09 22:06:38 浏览: 349
您可以使用h.set_cmap来将海洋填充颜色设置为灰色。具体实现方法如下:
fig = plt.figure(figsize=(11,8.5))
ax = fig.add_subplot(1,1,1, projection=ccrs.Mollweide())
h = ax.contourf(lon,lat,dat, levels=list(range(0,6,1)), extend='both', cmap='coolwarm', transform=ccrs.Mollweide())
c = ax.contour(lon,lat,dat, levels=list(range(0,6,2)), colors='k', linewidths=1, transform=ccrs.Mollweide())
ax.coastlines()
h.set_cmap('Greys')
相关问题
找出以下代码为什么保存的图有网格线: png = os.path.join(png_path, png_name) map_data = sunpy.map.Map(fits) fig_size = resolution/dpi fig = plt.figure(figsize=(fig_size, fig_size), dpi=dpi) fig.add_subplot([0, 0, 1, 1], projection=map_data) map_data.plot() plt.savefig(png)
根据你提供的代码,可以看到在保存图像之前,没有设置网格线的显示选项。但是如果保存的图像中包含网格线,有可能是因为在之前的代码中设置了 matplotlib 的全局参数来显示网格线。这些全局参数会影响所有之后创建的图形窗口。
你可以尝试在绘制图像之前,使用 `plt.grid(False)` 来关闭网格线的显示,然后再保存图像。以下是修改后的代码:
```python
import os
import sunpy.map
import matplotlib.pyplot as plt
png = os.path.join(png_path, png_name)
map_data = sunpy.map.Map(fits)
fig_size = resolution/dpi
fig = plt.figure(figsize=(fig_size, fig_size), dpi=dpi)
fig.add_subplot([0, 0, 1, 1], projection=map_data)
# 关闭网格线的显示
plt.grid(False)
map_data.plot()
plt.savefig(png)
```
通过添加 `plt.grid(False)` 可以确保在保存图像时不显示网格线。
希望这能解决你的问题!如果还有其他疑问,请随时提问。
fig, ax = plt.figure() TypeError: cannot unpack non-iterable Figure object
在Matplotlib中,当你尝试用`fig, ax = plt.figure()`创建一个新的图形和坐标轴时,错误信息"TypeError: cannot unpack non-iterable Figure object"通常是由于对`plt.figure()`返回的对象理解有误。
实际上,`plt.figure()`会直接返回一个`Figure`对象,这是一个单个的可视化窗口,而不是一个包含多个坐标轴的元组。如果你想在同一窗口内创建新的子图(axis),你应该这样做:
```python
import matplotlib.pyplot as plt
# 第一个子图
fig1 = plt.figure() # 或者不加变量名,直接plt.figure()
ax1 = fig1.add_subplot(111)
# 另一个子图(如果需要)
fig2 = plt.figure() # 或者使用共享的subplot_kw参数
ax2 = fig2.add_subplot(121, subplot_kw={'projection': 'polar'}) # 指定极坐标视图
# 现在你可以分别在ax1和ax2上绘制内容...
```
如果你确实需要在一个窗口内同时创建多个子图,可以使用`add_subplot`方法,并传递适当的参数来指定子图的位置和布局。
至于`fig, ax = plt.subplots()`则会按照你所期望的方式创建一个包含多个子图的容器。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)