我正在使用 matplotlib 绘制纬度经度坐标中的变量。问题是此图像不能包含轴或边框。我已经能够删除轴,但我的图像周围的白色填充必须完全删除(请参阅下面代码中的示例图像:http : //imgur.com/a/W0vy9)。
我尝试了 Google 搜索中的几种方法,包括这些 StackOverflow 方法:
如何删除 matplotlib 子图中的填充/边框(已解决)
但在去除空白方面没有任何作用。如果您有任何建议(即使是放弃 matplotlib 并尝试使用另一个绘图库),我将不胜感激!
这是我正在使用的代码的基本形式,它显示了这种行为:
import numpy as np
import matplotlib
from mpl_toolkits.basemap import Basemap
from scipy import stats
lat = np.random.randint(-60.5, high=60.5, size=257087)
lon = np.random.randint(-179.95, high=180, size=257087)
maxnsz = np.random.randint(12, 60, size=257087)
percRange = np.arange(100,40,-1)
percStr=percRange.astype(str)
val_percentile=np.percentile(maxnsz, percRange, interpolation='nearest')
#Rank all values
all_percentiles=stats.rankdata(maxnsz)/len(maxnsz)
#Figure setup
fig = matplotlib.pyplot.figure(frameon=False, dpi=600)
#Basemap code can go here
x=lon
y=lat
cmap = matplotlib.cm.get_cmap('cool') …Run Code Online (Sandbox Code Playgroud) 我使用ax.scatter(x,y,c=color, s=size, marker='*', label="mylabel")绘制在散点图中的4个符号(标志物是',','o','*',和'^'),每个具有不同的尺寸和颜色。
我试过打电话ax.legend(),虽然我得到了预期的标签信息,但没有任何标记出现在图例中。我尝试使用此处解释的许多变体但无济于事:http : //matplotlib.org/users/legend_guide.html
此外,我最终需要我的图例在一个完全独立的图像中。我试过: 在 Matplotlib 中获取图例作为单独的图片
和
https://pymorton.wordpress.com/2016/04/05/creating-separate-legend-figure-with-matplotlib/
但一直无法显示标记。任何意见,将不胜感激!
这是我的绘图代码:
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np
from scipy import stats
lat = np.random.randint(-60.5, high=60.5, size=257087)
lon = np.random.randint(-179.95, high=180, size=257087)
thiscategory = np.random.randint(12, 60, size=257087)
percRange = np.arange(100,40,-1)
#Rank all values
allPercent=stats.rankdata(thiscategory)/len(thiscategory)
h=np.where(allPercent > 0.9)
hl=np.where((allPercent <= 0.9) & (allPercent > 0.8))
mh=np.where((allPercent <= 0.8) & …Run Code Online (Sandbox Code Playgroud)