bastibe / Violinplot-Matlab

Violin Plots for Matlab
https://mathworks.com/matlabcentral/fileexchange/170126-violinplot-matlab
BSD 3-Clause "New" or "Revised" License
251 stars 105 forks source link

what are 'pos' and 'position' in the example code? #56

Closed germknoedlspeck closed 2 years ago

germknoedlspeck commented 2 years ago

Hi,

thank you for this excellent and versatile tool! I have a question regarding the example code in the readme:

grouporder={'England','Sweden','Japan','Italy','Germany','France','USA'};
vs = Violin({MPG(strcmp(Origin, grouporder{pos}))},...
    position,...
    'HalfViolin','right',...% left, full
    'QuartileStyle','shadow',... % boxplot, none
    'DataStyle', 'histogram',... % scatter, none
    'ShowNotches', false,...
    'ShowMean', false,...
    'ShowMedian', true,...
    'ViolinColor', color);

I tried executing both the preceding code snippet and this (i.e., load the data and reformat Origin to a cell), but this only throws the error that Matlab does not recognize the function or variable 'pos'. And I assume it will throw the same error with 'position' as well. What I wanted from the code snippets is to understand the expected format of my data for the Violin class. I have already used the function violinplots successfully, but now I want to visualise different distributions on the left and right sides of the violins.

I am using Matlab R2021b on a Windows 10 OS. Thank you in advance for your help!

mikelgg93 commented 2 years ago

Hi! the snippet tried to show a minimal example, I should probably modify it, but I did not find the time to do so. In general, the snippet posted above will only plot a single violin and is a small part of the whole code used for the figure on README.md. Anyway, pos is the argument I used to decide which country to plot. E.g. if you replace it with a 1, it should plot the data from England. On the other hand, position is another number, in this case, referring to the position of the violin plot on the X-axis. You may wanna pass this argument, for example, to plot one violin closer to another, as in the example Italy and Italy 1.5.

I hope this helps. Miguel

germknoedlspeck commented 2 years ago

Thank you for your quick answer 🎉