Remove Axis Tick Marks on a Seaborn Heatmap

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:26:36

6K+ Views

To remove the axis tick marks on a Seaborn heatmap, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create random data points with 4×4 dimension.Plot the rectangular data as a color-encoded matrix.Use tick_params() for changing the appearance of ticks and tick labels. Use left=false and bottom=false to remove the tick marks.To display the figure, use Show() method.Exampleimport numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(4, 4) ax = sns.heatmap(data, vmax=1) ax.tick_params(left=False, bottom=False) ... Read More

Logically Shade Region for a Curve in Matplotlib

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:25:07

214 Views

To make logically shading region for a curve in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create t, s1 and s2 data points using numpy.Create a figure and a set of subplots.Plot t and s1 data points; add a horizontal line across the axis.Create a collection of horizontal bars spanning *yrange* with a sequence of xranges.Add a '~.Collection' to the axes' collections; return the collection.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.collections as collections plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

Show Count Values on Top of a Bar in a Countplot using Matplotlib

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:23:54

11K+ Views

To show the count values on the top of a bar in a countplot, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe with one column.A countplot can be thought of as a histogram across a categorical, instead of a quantitative, variable.Iterate the returned axes of the countplot and show the count values at the top of the bars.To display the figure, use Show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt import numpy as np import pandas as pd plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

Increase Line Thickness of a Seaborn Line

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:21:02

3K+ Views

To increase the line thickness of a Seaborn line, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a Seaborn line plot with linewidth value in the argument. Here we have set linewidth=7.Rotate the tick params, i.e., labels by 45 degrees.To display the figure, use Show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt import pandas as pd import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(     dict(     ... Read More

Get Location and Sliced Index for Requested Label Level in Pandas

AmitDiwan
Updated on 19-Oct-2021 08:19:02

119 Views

To get location and sliced index for requested label/ level in a MultiIndex, use the get_loc_level() method in Pandas. Use the drop_level parameter and set it False to avoid dropping the level.At first, import the required libraries −import pandas as pdMultiIndex is a multi-level, or hierarchical, index object for pandas objects −multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')], names=['One', 'Two'])Display the MultiIndex −print("The MultiIndex...", multiIndex) Get the location and sliced index. To avoid dropping a level, we have used the "drop_level" parameter with value "False" −print("Get the location and sliced index (avoid dropping the level)...", multiIndex.get_loc_level('r', drop_level=False))ExampleFollowing is the code −import pandas as ... Read More

Adjust Space Between Matplotlib Seaborn Subplots

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:18:59

6K+ Views

To adjust the space between matplotlib/seaborn subplots for multi-plot layouts, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Adjust the subplot layout parameters.Create Seaborn's box plot for all the subplots.To display the figure, use Show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axes = plt.subplots(2, 2) # Adjust the subplot layout parameters fig.subplots_adjust(hspace=0.125, wspace=0.125) # Create Seaborn boxplot for all the subplots sns.boxplot(ax=axes[0, 0]) sns.boxplot(ax=axes[0, 1]) sns.boxplot(ax=axes[1, 0]) sns.boxplot(ax=axes[1, ... Read More

Sort Boxplot by Median Values in Pandas

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:17:33

1K+ Views

To sort a boxplot by the median values in Pandas, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe of two-dimensional, size-mutable, potentially heterogeneous tabular data, with three columns.Group the dataframe elements by marks and dob.Find the median of the dataframe.Get the sorted values of the median.Create a box plot from the DataFrame columns.To display the figure, use Show() method.Exampleimport pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame([     [23, 'James', 12],     [39, 'Jimmy', ... Read More

Get Location and Sliced Index for Requested Label Level in MultiIndex

AmitDiwan
Updated on 19-Oct-2021 08:16:13

182 Views

To get location and sliced index for requested label/ level in a MultiIndex, use the get_loc_level() method in Pandas.At first, import the required libraries −import pandas as pdMultiIndex is a multi-level, or hierarchical, index object for pandas objects −multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')], names=['One', 'Two'])Display the MultiIndex −print("The MultiIndex...", multiIndex) Get the location and sliced index −print("Get the location and sliced index...", multiIndex.get_loc_level('r'))ExampleFollowing is the code −import pandas as pd # MultiIndex is a multi-level, or hierarchical, index object for pandas objects multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')], names=['One', 'Two']) # display the MultiIndex print("The MultiIndex...", multiIndex) # get the ... Read More

Get Location for Sequence of Labels in a MultiIndex with Python Pandas

AmitDiwan
Updated on 19-Oct-2021 08:14:16

169 Views

To get location for a sequence of labels in a MultiIndex, use the MutiIndex.get_locs() method in Pandas.At first, import the required libraries −import pandas as pdMultiIndex is a multi-level, or hierarchical, index object for pandas objects −multiIndex = pd.MultiIndex.from_arrays([list('pqrrst'), list('kytssp')]) Display the MultiIndex −print("The MultiIndex...", multiIndex)Get the location for a sequence of labels −print("Get the locations in MultiIndex...", multiIndex.get_locs('s')) ExampleFollowing is the code −import pandas as pd # MultiIndex is a multi-level, or hierarchical, index object for pandas objects multiIndex = pd.MultiIndex.from_arrays([list('pqrrst'), list('kytssp')]) # display the MultiIndex print("The MultiIndex...", multiIndex) # get the levels in MultiIndex print("The ... Read More

Make Grouped Boxplot Graph in Matplotlib

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:12:54

3K+ Views

To make a grouped boxplot graph in matplotlib, we can take the following steps −Import matplotlib.pyplot and seaborn.Set the figure size and adjust the padding between and around the subplots.Load an example Seaborn dataset from the online repository.Make a boxplot with male and female group in a single day.To display the figure, use show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Import a Seaborn dataset data = sns.load_dataset('tips') # Create a grouped boxplot sns.boxplot(x=data['day'], y=data['total_bill'], hue=data['sex']) plt.show()OutputIt will produce the following ... Read More

Advertisements