Found 784 Articles for Data Visualization

How to plot a half-black and half-white circle using Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:19:01

1K+ Views

To plot a half-black and half-white circle using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Initialize theta1 and theta2 to draw edges from theta1 to theta2 and vice-versa.Add the wedge instance on the current axes.Set equal scaling by changing axis limits.Set x and y scale.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.patches import Wedge plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() theta1, theta2 = 0, 0 + 180 radius = 2 ... Read More

Change the default background color for Matplotlib plots

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:17:07

476 Views

To change the default background color for Matplotlib plots, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Get the current axis.Add a subplot to the current figure, with nrows=1, ncols=2 and index=1.Plot random x and y data points using plots() method.Set the title of the subplot.Add a subplot to the current figure with nrows=1, ncols=2 and index=2.Get the current axis.Set the customize face color.Plot x and y data points using plot() method.Set the title of the plot.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt ... Read More

How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:16:44

679 Views

To add a shared x-label and shared y-label, we can use plot() method with kind="bar", sharex=True and sharey=True.StepsSet the figure size and adjust the padding between and around the subplots.Create a two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot the dataframe with kind="bar", sharex=True and sharey=True.To display the figure, use show() method.Exampleimport pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(    {'First': [0.3, 0.2, 0.5, 0.2], 'Second': [0.1, 0.0, 0.3, 0.1],    'Third': [0.2, 0.5, 0.0, 0.7], 'Fourth': [0.6, 0.3, 0.4, 0.6]},    index=list('1234')) axes = df.plot(kind="bar", subplots=True, layout=(2, 2), ... Read More

How to plot a phase spectrum in Matplotlib in Python?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:14:08

1K+ Views

To plot a phase spectrum, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get random seed value.Initialize dt for sampling interval and find sampling frequency.Create random data points for t.To generate noise, get nse, r, cnse and s using numpy.Create a figure and a set of subplots using subplots() method.Set the title of the plot.Plot the phase spectrum.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 np.random.seed(0) dt = 0.01 # sampling interval Fs = 1 ... Read More

How can I generate more colors on a pie chart in Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:13:50

379 Views

To generate more colors on a pie chart in Matplotlib, we can generate n number of colors and dataStepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable, n, for number of data samples.Create random data points using numpy.Create a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Create a pie chart using pie() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import random import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True n = 40 color = ["#" + ... Read More

Vertical Histogram in Python and Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:13:32

1K+ Views

To plot vertical histogram in Python and Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of data points.Plot a histogram with vertical orientation.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 x = [1, 2, 3, 1, 2, 3, 4, 1, 3, 4, 5] plt.hist(x, orientation="vertical") plt.show()Output

How can I dynamically update my Matplotlib figure as the data file changes?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:13:15

2K+ Views

To update a Matplotlib figure as the data file changes, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize variables m and n, to get a set of subplots.Create a list of colors, to plot color dynamically.Plot dynamic data points using plot() method with random data points.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import random plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True m = 2 n = 4 fix, axes = plt.subplots(nrows=m, ncols=n) hexadecimal_alphabets = '0123456789ABCDEF' color = ["#" ... Read More

How to save Matplotlib 3d rotating plots?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:11:34

5K+ Views

To save Matplotlib 3d roatating 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.Return a tuple X, Y, Z with a test data set.Plot a 3D wireframe.Rotate the axis with an angle.Redraw the current figure.Run the GUI event loop for some seconds.To display the figure, use show() method.Examplefrom mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, ... Read More

How can I draw inline line labels in Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:11:12

2K+ Views

To draw inline labels in Matplotlib, we can use labelLines() method. −StepsSet the figure size and adjust the padding between and around the subplots.Create random data points x using numpy and a list of data points, A.Iterate the list of A, and plot X and a (iterated item) with label.Label all the lines with their respective legends, for lines drawn.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt from labellines import labelLines plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True X = np.linspace(0, 1, 500) A = [1, 2, 5, 10, 20] ... Read More

How to plot longitudinal magnitude spectrum in Matplotlib using Python?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:10:06

290 Views

To plot magintude spectrum, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get random seed value.Initialize dt for sampling interval and find the sampling frequency.Create random data points for t.To generate noise, get nse, r, cnse and s using numpyCreate a figure and a set of subplots using subplots() method.Set the title of the plot.Plot the longitudinal magnitude spectrum.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 np.random.seed(0) dt = 0.01 # sampling interval Fs ... Read More

Advertisements