File Exchange Pick of the Week

Our best user submissions

Subplot Position Calculator

吉罗‘s pick this week isSubplot Position CalculatorbyChristopher Hummersone.

子图is a nice way to place a grid of axes on a single figure. But the spacing is sometimes a bit too generous, leaving too little room for the graph.

nRows = 3; nCols = 2;form = 1:nRowsforn = 1:ncols子图(nrows,ncols,(m-1)*ncols+n)图(rand(20,1))endend

在这种情况下,您可以使用axes或者子图to specify the actual placement of the axes.

figure subplot('position',[0.05 0.1 0.45 0.8]) plot(rand(20,1)) subplot('position',[0.55 0.1 0.4 0.8]) plot(rand(20,1))

But this defeats the purpose of子图because you have to calculate and specify the position manually. This is where Christopher’s entry comes in handy. It lets you specify the grid layout, with optional parameters, and it returns a set of position vectors which you can feed into子图或者axes.

The default is a tight layout with no margin.

pos = iosr.figures.subfigrid(nRows,nCols); figureform = 1:nRowsforn = 1:nCols subplot('位置',pos(m,:,n)) plot(rand(20,1))endend

您可以通过几个可选参数来指定间距和缩放。

pos = iosr.figures.subfigrid(nRows,nCols,[0.1 0.05 0.05 0.1],[.95 .95]); figureform = 1:nRowsforn = 1:nCols subplot('位置',pos(m,:,n)) plot(rand(20,1))endend

As some of you may have guessed, his function is part of a包裹(IOSR MATLAB工具箱),其他功能也在他的另一个功能中突出显示File Exchange entries.

In addition to the usefulness of this function, I like Christopher’s entry because it is well-written with plenty of error-checking and has good help with examples. I haven’t had a chance to check out his other functions in his toolbox, but I would expect the same kind of quality as seen in this one.

评论

尝试一下,让我们知道您的想法这里或者leave acommentfor Christopher.




Published with MATLAB® R2017a

|
  • print
  • send email

评论

To leave a comment, please click这里to sign in to your MathWorks Account or create a new one.