Matplotlib Articles

Page 47 of 91

Changing the color and marker of each point using Seaborn jointplot

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 1K+ Views

To change the color and marker of each point using Seaborn jointplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Load an example dataset from the online repository (requires Internet).Use jointplot() method to plot tips data.Use cla() method to clear the current axes.Make a list of colors and markers for each point.Set the axes labels using set_axis_labels() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True tips = sns.load_dataset("tips") g ...

Read More

How to put text at the corner of an equal aspect figure in Python/Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 2K+ Views

To put text at the corner of an equal aspect figure in 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, using subplots() method.Create x data points using numpy.Plot x on axis ax1, using plot() method.Plot x and 2*x on ax2, using plot() method.To put text in the corner of a figure use annotate() method for different axes.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 fig, axes = plt.subplots(2) x ...

Read More

How can I add textures to my bars and wedges in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 585 Views

To add textures to bars and wedges 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 figure as part of a subplot arrangement.Make a list of hatches. Bars could be filled with some hatches.Create number bars as equivalent to number of hatches.Use bar() method to plot the bars with different hatch.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

How to plot cdf in Matplotlib in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 9K+ Views

To plot cdf in matplotlib in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable N for the number of sample data.Create random data using numpy.Compute the histogram of a set of data with data and bins=10.Find the probability distribution function (pdf).Using pdf (Step 5), calculate cdf.Plot the cdf using plot() method with label "CDF".Place a legend on the plot.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 N = 500 ...

Read More

How to adjust the branch lengths of a dendrogram in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 1K+ Views

To adjust the branch length of a dendrogram in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Draw random samples (a and b) from a multivariate normal distribution.Join a sequence of arrays along an existing axis, using concatenate() method.Perform hierarchical/agglomerative clustering.Create a new figure or activate an existing figure using figure() method.Add an axes to the figure as part of a subplot arrangement.Plot the hierarchical clustering as a dendrogram using dendrogram() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt from scipy.cluster.hierarchy import dendrogram, linkage import ...

Read More

How to add bold annotated text in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 2K+ Views

To add bold annotated text in matplotlib, we can use LaTeX representation for labels.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.To set the label for each scattered point, make a list of labels.Plot xpoints, ypoints using scatter() method. For color, use xpoints.Iterate zipped labels, xpoints and ypoints.Use annotate() method with bold LaTeX representation insie the for loop.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 xpoints = np.linspace(1, 10, 10) ypoints = np.random.rand(10) labels ...

Read More

How to plot half or quarter polar plots in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 1K+ Views

To plot half or quarter polar plots in 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 using figure() method.Add an axes to the figure as part of a subplot arrangement.For half or quarter polar plots, use set_thetamax() method.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 fig = plt.figure() ax = fig.add_subplot(111, projection="polar") max_theta = 90 ax.set_thetamax(max_theta) plt.show()Output

Read More

How to plot a point on 3D axes in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 6K+ Views

To plot a point on 3D axes in 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 using figure() method.Add an axes to the figure as part of a subplot arrangement, with 3d projection.To plot a point in 3d axes, use scatter() method.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 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(2, 3, 4, c='red', marker='*', s=1000) plt.show()Output

Read More

How to display a Dataframe next to a Plot in Jupyter Notebook?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 2K+ Views

To display a dataframe next to a plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with straight and square keys.Create a new figure or activate an existing figure using figure() method.Add a subplot to the figure with nrows=1, cols=2 and index=1.Plot dataframe points using scatter() method.Add subplot to the figure with nrows=1, cols=2 and index=2.Initialize variables font_size, bbox to make a table.Turn off the current axes.Add a table to the current axis using table() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import ...

Read More

Plotting histograms against classes in Pandas / Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 319 Views

To plot histograms against classes in Pandas/Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a potentially hetrogeneous tabular data using Pandas dataframe.Make a histogram from the DataFrame values.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': [1, 1, 1, 1, 3],'b': [1, 1, 2, 1, 3],'c': [2, 2, 2, 1, 3],    'd': [2, 1, 2, 1, 3],}) df.hist() plt.show()Output

Read More
Showing 461–470 of 902 articles
« Prev 1 45 46 47 48 49 91 Next »
Advertisements