Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
The matplotlib.pyplot.violinplot() is as the name explains is used for making violin plots. Through this function, you can make a violin plot for every column of the dataset or each vector in the dataset sequence. All filled areas extend to show the entire data range with lines that are optional at the mean, the median, the maximum and the minimum.
Syntax: matplotlib.pyplot.violinplot(dataset, positions=None, vert=True, widths=0.5, showmeans=False, showextrema=True, showmedians=False, points=100, bw_method=None, *, data=None)
- dataset: It is a required parameter that is generally an array or a sequence of vectors. This is where the data is fed to the function.
- positions: it is an array-like object whose default value is an array from 1 to n (ie, default = [1, 2, 3…n]). It is used to set the violins position. The limits and ticks are set automatically to match the positions.
- vert: This parameter accepts a boolean value. The default for this parameter is False. If set to True it creates a vertical violin plot else sets a horizontal violin plot.
- widths: It accepts an array-like object and has a default value of 0.5. It is used to set the maximal width of each violin and can be a scalar or a vector. If default value is used it takes about half the horizontal space.
- showmeans: it accepts a boolean value and has the default set as False. if set to true it toggles rendering of the mean
- showextreama: It accepts a boolean value and by default is set to False. if set True, it toggles rendering of the extrema.
- showmedians: It accepts a boolean value and has default set to False. If set True, it toggles the rendering of the medians.
- points:It accepts a scalar and has a default value of 100. it is used to define the total number of points to calculate every gaussian kernel density estimations.
- bw_method: It is an optional parameter that accepts a string, scalar or a callable. The estimator bandwidth is calculated using this method. It can be ‘silverman’, ‘scott’, a callable or a scalar constant. In case of scalar, it is used directly as kde.factor. If it is a callable then it takes GaussianKDE instance only and returns a scalar. Scott is used in case None
Returns: This function returns a dictionary mapping of each component of the violin-plot to a list of respective collection instances. the dictionary returned has the following keys:
- bodies: AN instance list of matplotlib.collections.PolyCollection containing the filled area of every violin.
- cmeans: An instance of matplotlib.collections.LineCollection is created to identify the mean of each violin distribution
- cmins: An instance of matplotlib.collections.LineCollection created to identify the bottom of each violin distribution.
- cmaxes: An instance of matplotlib.collections.LineCollection created to identify the top of each violin distribution.
- cbars:An instance of matplotlib.collections.LineCollection created to identify the center of each violin distribution.
- cmedians:An instance of matplotlib.collections.LineCollection created to identify the mean value of each violin distribution.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
- twitter-text-python (ttp) module - Python
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python program to check if the list contains three consecutive common numbers in Python
- Creating and updating PowerPoint Presentations in Python using python - pptx
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.