The Pandas plotting function boxplot() used to make a box plot from DataFrame columns. It makes a box-and-whisker plot from DataFrame columns, optionally grouped by some other columns. A box plot is a method for graphically depicting groups of numerical data through their quartiles.
1 pandas.plotting.boxplot(data, column = None, by = None, ax = None, fontsize = None, rot = 0, grid = True,
2 figsize = None, layout = None, return_type = None, **kwargs)
data : It is a DataFrame object to visualize data on graph.
column : It is a string, list[str] that specifies a column name or list of names or vector. It can be any valid input to pandas DataFrame.groupby()
by : It is a string or array that represents the column in the DataFrame to pandas.DataFrame.groupby(). One box-plot will be done per value of columns in by.
ax : It is an object of class matploatlib.axes.Axes that specifies the matplotlib axes to be used by boxplot.
fontsize : It can be float or string that ticks label font size in points or as a string. ie. large.
rot : It is a float that specifies the rotation angle of labels (in degrees) with respect to the screen coordinate system. If not specifies, the default value will be 0.
grid : It is a boolean that specifies whether to show the grid. If not specified, the default value will be True.
figsize : It is a tuple that includes width and height in inches, specifies the size of the figure to create in matplotlib.
layout : It is a tuples that includes rows and columns, display the subplots starting from the top-left.
return_type : It can be axes, dict, both or None. If not specified, the default value will be axes.
1. | axes : If specified, it returns the matplotlib axes the boxplot is drawn on. |
2. | dict : If specified, it returns a dictionary that includes values which are the matplotlib Lines of the boxplot. |
3. | both : If specified, it returns a namedtuple with the axes and dict. |
Note : If grouping with by, a Series mapping columns to return_type is returned, if return_type is None, a NumPy array of axes with the same shape as layout is returned.
**kwargs : It specifies an additional keywords to be passed to the function matploatlib.pyplot.boxplot().
1 import pandas as pd
2 import numpy as np
3 import matplotlib.pyplot as plt
4
5 np.random.seed(1234)
6 cls = ['C1', 'C2', 'C3', 'C4']
7 df = pd.DataFrame(np.random.randn(10, 4), columns = cls)
8 res = df.boxplot(column = cls)
9
10 res.plot()
11 plt.show()
In the above example, a DataFrame object is created by passing a data and columns. A boxplot() function is called that plot data on graph and visible on screen.
Related options for your search