Found 784 Articles for Data Visualization

Plotting a heatmap for 3 columns in Python with Seaborn

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:49:00

1K+ Views

To plot a heatmap for 3 columns in Python with Seaborn, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dataframe, df, with 3 columns.Plot the rectangular data as a color-encoded matrix.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((3, 3)), columns=["a", "b", "c"]) sns.heatmap(df, cbar=False) plt.show()Output

What is the equivalent of Matlab's surf(x,y,z,c) in Matplotlib?

Rishikesh Kumar Rishi
Updated on 21-Oct-2021 08:48:15

617 Views

Let's take an example to see how to get the same effect as MatLab's surf(x, y, z, c) in Matplotlib. steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Create r, u, v, x, y and z data points using Numpy.Create a surface plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(projection='3d') r = 0.05 u, v ... Read More

How to plot two histograms side by side using Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:45:16

12K+ Views

To plot two histograms side by side using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make two dataframes, df1 and df2, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a figure and a set of subplots.Make a histogram of the DataFrame's, df1 and df2.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df1 = pd.DataFrame(dict(a=[1, 1, 1, 1, 3])) df2 = pd.DataFrame(dict(b=[1, 1, 2, 1, 3])) fig, axes = plt.subplots(1, 2) ... Read More

How to make a circular matplotlib.pyplot.contourf?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:43:03

593 Views

To make a circular matplotlib.pyplot.contourf, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y, a, b and c data points using Numpy.Create a figure and a set of subplots.Make a Contour plot using contourf() method.Set the aspect ratios.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-0.5, 0.5, 100) y = np.linspace(-0.5, 0.5, 100) a, b = np.meshgrid(x, y) c = a ** 2 + b ** 2 - 0.2 ... Read More

How to set the background color of a column in a matplotlib table?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:40:23

1K+ Views

To set the background color of a column in a matplotlib table, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a tuple for columns attribute.Make a list of lists, i.e., list of records.Make a list of lists, i.e., color of each cell.Create a figure and a set of subplots.Add a table to an axes, ax.Turn off the axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True columns = ('name', 'age', 'marks', 'salary') cell_text = [["John", "23", "98", "234"], ... Read More

How to properly enable ffmpeg for matplotlib.animation?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 09:20:01

3K+ Views

To enable ffmpeg for matplotlib.animation, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Set the ffmpeg directory.Create a new figure or activate an existing figure, using figure() method.Add an 'ax1' to the figure as part of a subplot arrangement.Plot the divider based on the pre-existing axes.Create random data to be plotted, to display the data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance, cb.Set the title as the current frame.Make a list of colormaps.Make an animation by repeatedly calling a function, animate. The ... Read More

What are n, bins and patches in matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 07:32:56

1K+ Views

The hist() method returns n, bins and patches in matplotlib. Patches are the containers of individual artists used to create the histogram or list of such containers if there are multiple input datasets. Bins define the number of equal-width bins in the range.Let's take an example to understand how it works.stepsSet the figure size and adjust the padding between and around the subplots.Create random data points using numpy.Make a Hist plot with 100 bins.Set a property on an artist object.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

How to get all the legends from a plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:59:56

1K+ Views

To get all the legends from a plot in matplotlib, we can use the get_children() method to get all the properties of an axis, then iterate all the properties. If an item is an instance of a Legend, then get the legend texts.stepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Create a figure and a set of subplots.Plot sin(x) and cos(x) using plot() method with different labels and colors.Get the children of the axis and get the texts of the legend.To display the figure, use show() method.Exampleimport numpy as np from ... Read More

Plot a multicolored line based on a condition in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:55:26

3K+ Views

To plot a multicolored line based on a condition in Python Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create y data points using numpy.Make l and u data points to differentiate the colors.Plot the u and l data points using plot() method, with different colors.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True y = np.sin(np.linspace(-10, 10, 100)) u = y.copy() l = y.copy() u[u = 0] = np.nan plt.plot(u, color='red') ... Read More

How to create a Boxplot with Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:52:19

154 Views

To create a Boxplot with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of xticks.Plot a boxplot with xticks data.Set xticks and xtick labels with 45° rotation.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xticks = [1, 4, 5, 2, 3] ax = sns.boxplot(xticks) ax.set_xticks(xticks) ax.set_xticklabels(["one", "two", "three", "four", "five"], rotation=45) plt.show()Output

Advertisements