Plot Hatched Bars Using Pandas and Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:18:35

2K+ Views

To plot hatches bars using Pandas, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a dataframe using Pandas with two columns.Add an axes to the current figure as a subplot arrangement.Make a plot with kind="bars" class by name.Make a list of hatches.Get the bars patches using bars.patches.Iterate bars patches and set the hatch of each patch.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.rand(5, 2), columns=['a', ... Read More

Surface Plot 3D Plot from DataFrame using Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:17:16

3K+ Views

To surface plot/3d, we would require 2D data points, not 1D dataframe.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.Initialize a variable 'n' for the number of samples.Create x, y and z data points using numpy.Use plot_surface() method to make surface 3d.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = ... Read More

Show Different Colors for Points and Line in Seaborn Regplot

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:16:04

3K+ Views

To show different colors for points and line in a Seaborn regplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with key X-axis and Y-axis.Plot numeric independent variables with regression model.To display the figure, use show() method.Exampleimport pandas import matplotlib.pylab as plt import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pandas.DataFrame({"X-Axis": [np.random.randint(5) for i in range(10)], "Y-Axis": [np.random.randint(5) for i in range(10)]}) sns.regplot(x='X-Axis', y='Y-Axis', data=df, scatter_kws={"color": "red"}, line_kws={"color": "green"}) plt.show()OutputRead More

Render 3D Histograms in Python Using Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:14:55

4K+ Views

To render 3D histograms in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an axes to the cureent figure as a subplot arrangement.Create x3, y3 and z3 data points using numpy.Create dx, dy and dz data points using numpy.Use bar3d() method to plot 3D bars.To hide the axes use axis('off') class by name.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

Add Legend to Matplotlib Boxplot with Multiple Plots

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:12:54

3K+ Views

To add a legend to a matplotlib boxplot with multiple plots on the same axis, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data, a and b, using numpy.Create a new figure or activate an existing figure using figure() method.Add an axes to the current figure as a subplot arrangement.Make a box and whisker plot using boxplot() method with different facecolors.To place the legend, use legend() method with two boxplots, bp1 and bp2, and ordered label for legend elements.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt ... Read More

Plot Data Against Specific Dates on X-Axis Using Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:11:30

3K+ Views

To plot data against specific dates on the X-axis using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of dates and convert them in datetime format as x.Make a list of y data points.Set the formatter of the major ticker.Set the locator of the major ticker.Plot x and y data points using plot() method.To display the figure, use show() method.Examplefrom datetime import datetime from matplotlib import pyplot as plt, dates as mdates plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True dates = ["01/02/2021", "01/03/2021", "01/04/2021", ... Read More

Draw Average Line for Scatter Plot in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:10:09

3K+ Views

To draw an average line for a plot in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make x and y data points using numpy.Use subplots() method to create a figure and a set of subplots.Use plot() method for x and y data points.Find the average value of the array, x.Plot x and y_avg data points using plot() method.Place a legend on the figure.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x ... Read More

Remove X or Y Labels from a Seaborn Heatmap

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:08:58

8K+ Views

To remove X or Y labels from a Seaborn heatmap, we can use yticklabel=False.StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with 5 columns.Use heatmap() method to plot rectangular data as a color-encoded matrix with yticklabels=False.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["col1", "col2", "col3", "col4", "col5"]) sns.heatmap(df, yticklabels=False) plt.show()OutputRead More

Display Seaborn and Matplotlib Plots with Dark IPython Notebook Profile

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:05:32

362 Views

To display a Seaborn/Matplolib plot with a dark background, we can use "dark" in set_style() method that gives an aesthetic style to the plots.StepsSet the figure size and adjust the padding between and around the subplots.Use "dark" in set_style() method that sets the aesthetic style.Create a Pandas dataframe with two columns.Show point estimates and confidence intervals with bars, using bar plot() method.Rotate xticks by 45 degrees.To display the figure, use show() method.Exampleimport pandas import matplotlib.pylab as plt import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True sns.set_style("dark") df = pandas.DataFrame({"X-Axis": [np.random.randint(10) ... Read More

Automatic Detection of Display Availability with Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:04:06

253 Views

To detect display availability with matplotlib, we can take the following steps −StpsImport os module.Use os.environ["DISPLAY"] to get the available display.Exampleimport os env = os.environ["DISPLAY"] print("Automatic detected display availability: ", env)OutputAutomatic detected display availability: 0

Advertisements