A rug plot is used to plot marginal distributions by drawing ticks along the x and y-axis. A rug plot is often used along with other plots to show the distribution of data along the x-axis and the y-axis. Let’s look at an example first.
We will read the tips dataset from the seaborn library. The dataset contains various information, such as total bill, tip amount, etc. Let’s say we want to see the relationship between the total bill and the tip amount. For that purpose, we can plot a scatter plot. And we can use a rug plot along with the scatter plot. As a result, the rug plot will show the distribution of the total bill and the tip amount along the x-axis and the y-axis using ticks.
We can use the following Python code to plot a rug plot along with a scatter plot using the seaborn Python library.
import seaborn from matplotlib import pyplot df = seaborn.load_dataset("tips") seaborn.scatterplot(data=df, x="total_bill", y="tip") seaborn.rugplot(data=df, x="total_bill", y="tip") pyplot.savefig("seaborn-rugplot.png") pyplot.close()
Here, the scatterplot will show the relationship between the total bill amount and the tip amount. And the rug plot will show the distribution of the total bill and tips along with the x and y axis, respectively. The resulting plot will look like the following:
0 Comments