piermorel / gramm

Gramm is a complete data visualization toolbox for Matlab. It provides an easy to use and high-level interface to produce publication-quality plots of complex data with varied statistical visualizations. Gramm is inspired by R's ggplot2 library.
MIT License
784 stars 222 forks source link

Bug with update when keeping the same axes #137

Open piermorel opened 4 months ago

piermorel commented 4 months ago

Hi, thanks for this great package! I come from R, now programming in Matlab and was super happy to find your package :). I was wondering if there is a way to plot two data sets in the same graph. Let's say I have one data set that I want to use to plot a line, and another to plot data points. I found the update() function, but I can't manage to plot the data on the same axes.

% Data for lines
x_line = 1:10;
y_line = sin(x_line);

% Data for points
x_points = 1:0.5:10;
y_points = cos(x_points);

% Create a gramm object with the line data
clear g
g = gramm('x',x_line,'y',y_line);

% Add a line layer
g.geom_line();

% Draw the lines
figure('Position',[100 100 800 600]);
g.draw(); 

% Update x and y values for the data points
g.update('x', x_points,'y',y_points, 'color', y_points);

% Add a point layer with the second data set
g.geom_point();
g.set_color_options();

% Draw data points
g.draw();

This is what I get:

ExamplePlot

Moreover, I needed to define the y_points as color argument to be able to see the data points at all. Would be happy to have them just in the same color as the lines. Do you have an advice for me? Thanks in advance!

Originally posted by @svenjakemmer in https://github.com/piermorel/gramm/issues/31#issuecomment-2112491166