Found 784 Articles for Data Visualization

How to change the line color in a Seaborn linear regression jointplot?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:38:51

660 Views

To change the line color in seaborn linear regression jointplot, we can use joint_kws in jointplot() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy to make a Pandas dataframe.Use jointplot() method with joint_kws in the arguments.To display the figure, use show() method.Exampleimport seaborn as sns import numpy as np from matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True X = np.random.randn(1000, ) Y = 0.2 * np.random.randn(1000) + 0.5 df = pd.DataFrame(dict(x=X, y=Y)) g = sns.jointplot(x="x", y="y", ... Read More

Controlling the width of bars in Matplotlib with per-month data

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:36:24

495 Views

To control the width of bars in matplotlib with per-month data, we can take the following steps −Set the figure size and adjust the padding between and around the subplotsMake a list of dates, x and y, using numpy.Plot the bar with x and y data points, with per-month data.To display the figure, use show() method.Exampleimport numpy as np import datetime from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [datetime.datetime(2021, 1, 1, 0, 0),    datetime.datetime(2021, 2, 1, 0, 0),    datetime.datetime(2021, 3, 1, 0, 0),    ] y = ... Read More

How to animate a sine curve in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:32:48

2K+ Views

To make animated sine curve, 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.Add an axes to the current figure and make it the current axes.Plot a line with empty lists.To initialize the line, pass empty lists.To animate the sine curve, update sine curve values and return the line instance.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt from matplotlib import animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax ... Read More

Matplotlib histogram with multiple legend entries

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:28:05

3K+ Views

To plot a histogram with multiple legend entries, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data using numpyPlot a histogram using hist() method.Make a list of colors to color the face of each patch.Iterate the patches and set face color of each patch.Create a list of handles to place the legend.Use legend() method for multiple legend entries.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Rectangle plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rayleigh(size=1000) * ... Read More

Differentiate the orthographic and perspective projection in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:25:33

443 Views

To plot perspective and orthographic projection plots, 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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Set the projection type as 'perspective' on ax1 axis.Set the title of the plot.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Set the projection type as 'orthographic' on ax2 axis.Set the title of the plot.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 fig ... Read More

How to create a Matplotlib bar chart with a threshold line?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:20:34

3K+ Views

To create a Matplotlib bar chart with a threshold line, we have to use axhline() method.StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable, threshold.Make lists for bars values.Get the below and above bar values based on the threshold value.Create a figure and a set of subplots using subplots() method.Plot bars with x, a_threshold and b_threshold values.Add a horizontal line across the axis using axhline() method.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 threshold = 10 values = np.array([8.0, 10.0, ... Read More

How to plot a remote image from http url using Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:18:42

2K+ Views

To plot a remote image from an http URL, we can use io.imread() method to read an URL and take the following steps −Set the figure size and adjust the padding between and around the subplots.Load an image from an http URLUse imshow() method to display data as an image, i.e., on a 2D regular raster.Turn off the axes.To display the figure, use show() method.Examplefrom skimage import io import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True f = "http://matplotlib.sourceforge.net/_static/logo2.png" a = io.imread(f) plt.imshow(a) plt.axis('off') plt.show()OutputRead More

How to add text inside a plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:16:46

9K+ Views

To add text inside a plot in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Place text with some text properties.Plot x and y using plot() method.Turn off the axes.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 = np.linspace(-5, 5, 100) y = x ** 3 plt.text(0, 100, '$y=x^3$', fontsize=22, bbox=dict(facecolor='red', alpha=0.5)) plt.plot(x, y, c='g') plt.axis('off') plt.show()OutputRead More

How to place X-axis grid over a spectrogram in Python Matplotlib?

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

369 Views

To place X-axis grid over a spectrogram in Python, we can use grid() method and take the following steps −Set the figure size and adjust the padding between and around the subplots.Create t, s1, s2, nse, x, NEFT and Fs data points using numpy.Create a new figure or activate an existing figure using subplots() method with nrows=2.Plot t and x data points using plot() method.Lay out a grid in current line style.Set X-axis margins.Plot a spectrogram using specgram() method.Lay out a grid in current line style with dotted linestyle and some other properties.To display the figure, use show() method.Exampleimport matplotlib.pyplot ... Read More

How to hide axes but keep axis-labels in 3D Plot with Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 09:11:21

2K+ Views

To hide axes but keep axis-labels in 3D plot with Matplotlib, 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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Create x, y, z, dx, dy and dz data points using numpyUse bar3d() method to plot the 3D bars.To hide the axes, initialize a color tuple, the same as axes color.Set x, y and z axes plane color property same with the color tuple.Set x, y and z axes line color property ... Read More

Advertisements