Creating Stunning Visualizations with Gramm in MATLAB

Dec 26, 2021 | Data Science

Gramm is a MATLAB toolbox that simplifies the creation of complex, publication-quality figures. By adopting a declarative approach, Gramm allows users to specify the desired result without delving into traditional iterative methods. Drawing inspiration from the grammar of graphics principles and libraries like ggplot2, it enables quick and efficient data visualization.

Installation of Gramm

To get started with Gramm, you can install it directly through MATLAB’s Add-ons explorer. Simply search for gramm and click Add! Alternatively, you can manually download the latest .mltbx file or add the Gramm folder from the repository to your MATLAB path.

Workflow to Generate Figures

Using Gramm is like conducting an orchestra. Each instrument (data variable) contributes to the symphony (the figure). With only a few lines of code, you can produce vibrant visualizations that harmonize data effectively. Here’s how you can do it:

  • Step 1: Prepare Your Data

    Provide the relevant data for the figure, specifying your X and Y variables, along with grouping variables for color and facets.

    matlab
    load example_data.mat  % Load example dataset about cars
    g = gramm(x, cars.Model_Year, y, cars.MPG, color, cars.Cylinders, subset, ~mod(cars.Cylinders, 2));
    g.facet_grid([], cars.Origin_Region);
    
  • Step 2: Add Graphical Layers

    This step is akin to adding notes to the score. You can plot raw data points or apply statistical layers with just one line of code each.

    matlab
    g.geom_point(dodge, 0.5);  % Plot raw data as points
    g.stat_glm();  % Plot linear fits of the data
    
  • Step 3: Configure the Figure

    This involves adjusting titles, legends, and aesthetics, similar to fine-tuning the sound of each instrument.

    matlab
    g.set_names(column, Origin, x, Year of production, y, Fuel economy (MPG), color, # Cylinders);
    g.set_title(Fuel economy of new cars between 1970 and 1982);
    
  • Step 4: Draw the Figure

    Finally, the orchestra plays together, and Gramm takes care of the technical details, providing beautifully arranged figures without the hassle of manual adjustments.

    matlab
    g.draw();
    

Troubleshooting Tips

If you encounter issues while using Gramm, here are some troubleshooting ideas:

  • Ensure that you’ve correctly added the Gramm folder to your MATLAB path.
  • Verify that your data is formatted correctly; mismatched dimensions can lead to errors.
  • Consult the documentation by typing doc in the MATLAB command window for specific command syntax and options.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Main Features of Gramm

Gramm packs a punch with its myriad capabilities:

  • Accepts variably shaped X, Y, Z, and grouping data.
  • Offers multiple ways of visually differentiating data, including colors, sizes, and styles.
  • Supports various plot types, from scatter plots to box plots and advanced statistical visualizations.
  • Customizes groupings extensively through colormaps and ordering.
  • Exports visualizations in multiple formats maintaining aspect ratios.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox