Found 784 Articles for Data Visualization

How to make an arrow that loops in Matplotlib?

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:40:03

125 Views

To make an arrow that loops in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.To make an arrow loop in matplotlib, we can use make_loop() method.Make a wedge instance with center, radius, theta1, theta2 and width.To put the arrow top of the loop, use PathCollection.Add patch collection to the current axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches, collections plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def make_loop(center, radius, theta1=-30, theta2=180):    rwidth = 0.02    ring = patches.Wedge(center, radius, theta1, ... Read More

How to plot an angle spectrum using Matplotlib in Python?

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:39:41

422 Views

To plot an angle 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 numpy.Create a figure and a set of subplots using subplots() method.Set the title of the plot.Plot the angle 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

How to change the datetime tick label frequency for Matplotlib plots?

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:34:41

5K+ Views

To change the datetime tick label frequency for Matplotlib plots, we can create a dataframe and plot them in some date rangeStepsSet the figure size and adjust the padding between and around the subplots.To make potentially heterogeneous tabular data, use Pandas dataframe.Plot the dataframe using plot() method.Set X-axis major locator, i.e., ticks.Set X-axis major formatter, i.e., tick labels.Use autofmt_xdate(). Date ticklabels often overlap, so it is useful to rotate them and right align them.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates plt.rcParams["figure.figsize"] = [7.50, ... Read More

How to add a legend to a Matplotlib pie chart?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:22:53

7K+ Views

To add a legend to a Matplotlib pie chart, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of labels, colors, and sizes.Use pie() method to get patches and texts with colors and sizes.Place a legend on the plot with patches and labels.Set equal scaling (i.e., make circles circular) by changing the axis limits.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 labels = ['Walk', 'Talk', 'Sleep', 'Work'] sizes = [23, 45, 12, 20] colors = ['red', 'blue', ... Read More

How to make more than 10 subplots in a figure using Matplotlib?

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

857 Views

To make more than 10 subplots in a figure, we can use subplots() method with some rows and columns.StepsSet the figure size and adjust the padding between and around the subplots.Initialize rows count and columns count.Create a figure and a set of subplots with rows☓cols subplots.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True rows = 4 cols = 3 fig, axes = plt.subplots(nrows=rows, ncols=cols) plt.show()Output

How to plot a jointplot with 'hue' parameter in Seaborn? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:20:58

312 Views

To plot a jointplot with hue parameter in Seaborn, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Make a dictionary with some curve data.Make a dataframe for tabular data.Make a jointplot using jointplot() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 1, 5) d = {       'y=sin(x)': np.sin(x),       'y=cos(x)': np.cos(x), ... Read More

How do you change the default font color for all text in Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:23:21

3K+ Views

To change the default font color for all text in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Using rcParams['text.color'], we can get the default text color.We can update the text color and label color after updating the rcParams dictSet the title and label 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 print("Default text color is: ", plt.rcParams['text.color']) plt.rcParams.update({'text.color': "red",                      'axes.labelcolor': "green"}) plt.title("Title") plt.xlabel("X-axis") plt.show()OutputRead More

How to annotate the end of lines using Python and Matplotlib?

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

1K+ Views

To annotate the end of lines using Python and Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initalize a variable, rows, to get the number of rows data.Get a Pandas dataframe in a rectangular tabular data.Calculate the cumsum (cumulative sum) of the dataframe.Plot the dataframe using plot() method.Iterate line and name to annotate the end of lines.Use annotate() method with column's name, xy co-ordinates, color of the lines, sizes, etc.Place a legend on the figure.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import ... Read More

Defining multiple plots to be animated with a for loop in Matplotlib

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

2K+ Views

To define multiple plots to be animated with a for loop in matplotlib, we can take followings 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 current figure and make it the current axes.Initialize two variables, N and x, using numpy.Get the list of lines and bar patches.Animate the lines and rectangles (bar patches) in a for loop.Make an animation by repeatedly calling a function *func*.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt from matplotlib import ... Read More

How to return a matplotlib.figure.Figure object from Pandas plot function?

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

546 Views

To return a matplotlib.figure.Figure object from Pandas function, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe, df.Make a horizontal bar plot using barh() method.Get the current figure instance.Place a legend on the axes at the lower-right location.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 df = pd.DataFrame({'a': range(10)}) ax = df.plot.barh(color=(1, 0, 0, 0.25)) fig = ax.get_figure() ax.legend(loc='lower right') plt.show()OutputRead More

Advertisements