2

I would like to create an MxN grid of charts - similar to

for i in M*N:
   ax = fig.add_subplot(M, N, i + 1)

for matplotlib

There appears to be supporting classes - within the org.jfree.chart.block package. However I have been unable to locate documentation, examples, testcases for using that arrangement/layout with a set of charts.

Pointers appreciated.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

2 Answers2

2

This part of the API is rather low-level, and mostly used internally by JFreechart. For example, GridArrangement may be used to create a particular legend layout, within a chart.

In my opinion, the easiest way to create a grid of charts, is to use a Swing JPanel and a GridLayout, and fill that grid with your charts.

JPanel grid = new JPanel( new GridLayout(m,n) );
for(int i=0; i<m*n; i++)
   grid.add(new ChartPanel(createChart(i)));

You can also use a CombinedPlot. This allows to add as many plots as you want, either layed out side-by-side, or stacked vertically (but not on a grid, as far as I know). The good thing with this approach is that your plots will directly share a common axis, and will be aligned nicely. (But that depends on your problem: do your charts share one common axis ? Perhaps two ?)

Community
  • 1
  • 1
Eric Leibenguth
  • 4,167
  • 3
  • 24
  • 51
  • There's a related example [here](http://stackoverflow.com/a/11895709/230513) that illustrates `CombinedDomainXYPlot`. – trashgod Aug 03 '15 at 11:18
  • I am using CombinedPlot now - but yes they only have the side-by-side or stacked. May I put the CombinedPlot inside a GridLayout? That is my next experiment. – WestCoastProjects Aug 03 '15 at 14:29
2

To arrange the chart panels in a grid, use a GridLayout() on the enclosing container, as shown in this related example:

f.setLayout(new GridLayout(M, N));
f.add(new ChartPanel(chart1));
f.add(new ChartPanel(chart2));
…

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Helpful - I will award to @Eric since he actually addresses the use of GridArrangement and also mentions the CombinedPlot: a bit more complete answer. – WestCoastProjects Aug 03 '15 at 14:31
  • I agree; more size options are suggested [here](http://stackoverflow.com/a/10277372/230513). – trashgod Aug 03 '15 at 15:21