To specify a sub-plot position, you pass the keyboard “position” as the first argument in subplot(), followed by a 1 x 4 vector that describes the position. If you are unfamiliar with relative figure units, you can see a previous tutorial that covered these. This is most easily done by using normalized figure units and specifying relative offsets within the figure. ![]() The final and most flexible way to use the subplot() function is to directly specify the position of the axes. Image by author Using Position Coordinates In all cases, the linear indices have been included over the plots to illustrate which parts of the grid they are covering. Finally, the last sub-plot is in the bottom right corner and spans the last two rows. The second sub-plot is placed in the bottom left corner and covers a 2 x 2 sub-grid. The first sub-plot is placed at the top of the grid and spans all three columns. This method lets you make some really nice looking plots that can easily accommodate various types of data. So for example, subplot( 1, 3, ) would create a subplot grid that has three columns and a single plot that occupies the first two columns. This is accomplished by passing in an array of linear indices as third argument, rather than just a single value. Image by author Using Different Sized PlotsĪ slightly more flexible way of using subplot() is to place sub-plots over multiple points in the grid. For convenience, I have also used the text() function to display the linear index in each subplot. Let’s start with a simple example that includes three sub-plots along a single row. It’s OK if this doesn’t make sense yet, the ordering is visualized in all of the examples within this section, and is especially obvious in the grid example. The index starts at 1 and increases from left to right and top to bottom. The third argument is a linear index that selects the current active plot axes. The first two arguments define the number of rows and columns that will be included in the grid. The basic form of the subplot() command takes in three inputs: nRows, nCols, linearIndex. The subplot() function in MATLAB/Octave allows you to insert multiple plots on a grid within a single figure. The source code for the included examples can be found in the GitHub repository. The provided examples work in both MATLAB and Octave. In this tutorial, I describe three different ways to use the subplot() command and provide examples of each. They can also be used to quickly create interactive Graphical User Interfaces (GUIs). They allow users to very quickly create customized data visualizations and displays. This will create a static text box of width 100 pixels and height 25 pixels placed at the center of the top of the figure and with the same background color as the figure.Sub-plotting is a very powerful feature in MATLAB. You can get the size and the position of the figure first to help you place the text box near the top and center: figureSize = get(gcf,'Position') To add a title to the entire figure, the best option is probably to make a UICONTROL static text object and adjust its position so it is placed near the top of the figure. Second, you can convert one long label into a multi-line label by using a cell array of strings instead of just a single string: ylabel() First, you can adjust the font size in your call to YLABEL: ylabel('Number of Occurrences','FontSize',7) You have a couple of options to fix this. However, you'll likely notice that your y-axis labels in particular may end up being written over one another if they are too long. ![]() That will take care of one axis label problem. For the axis labels, Matt is correct about them having to be placed after the call to BAR.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |