Matplotlib删除补丁周围的空白

时间:2018-11-17 13:39:20

标签: python matplotlib

在下图(1)中,六角形网格周围有很多白色空间,我无法弄清楚该如何去除。我尝试了不同的方法,例如[Activity(Label = "fooApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init(); LoadApplication(new App()); } }

SOM Hitmap

代码是

tight_layout

可以由import matplotlib.pyplot as plt from matplotlib.patches import RegularPolygon import matplotlib.cm as cm import matplotlib.colors as colors import numpy def plot_som_hm(hm,colormap,a=1): # setup hexagon offsets m,n = hm.shape offsety = .75 * 2*a offsetx = numpy.sqrt(3) * a evenrow = numpy.sqrt(3)/2 * a # set up the figure fig,ax = plt.subplots(figsize=(2,2)) ax.set_aspect('equal') # define colormap cmap = cm.ScalarMappable(None,colormap) norm = colors.Normalize(vmin=hm.min(),vmax=hm.max()) # iterate over the hitmap, drawing a hexagon xs = [] ys = [] for i in range(m): for j in range(n): # calculate center point for current hexagonal grid & draw it offsetr = evenrow if i % 2 == 0 else 0 x,y = (j*offsetx+offsetr,-i*offsety) hexg = RegularPolygon( (x,y),numVertices=6,radius=a,facecolor=cmap.cmap(norm(hm[i][j])) ) ax.add_patch(hexg) xs.append(x) ys.append(y) # add a scatter plot so all hexagons show up & turn off ticks ax.scatter(xs,ys,alpha=1.0) ax.set_xticks([]) ax.set_yticks([]) # add a colorbar sm = plt.cm.ScalarMappable(cmap=colormap,norm=norm) sm._A = [] plt.colorbar(sm,ticks=range(int(hm.min()),int(hm.max())+1)) # and show the hitmap plt.show()

调用

我不确定空格是否是调用子图plot_som_hm(hitmap,'inferno',-0.5)或其他东西的结果。我对(figsize=(2,2))相对陌生,我不确定空格是从哪里来的,也就是说,它是数字,轴甚至是matplotlib的来源,因此在Google上进行搜索并没有提供任何相关的答案。

1 个答案:

答案 0 :(得分:1)

II建议阅读x和y限制,以了解如何根据需要调整它们:

print(ax.get_xlim())

然后例如

ax.set_xlim(0.5, 5.5)

或其他合适的方式。

与y轴相同。