Found 1034 Articles for Matplotlib

How to determine the order of bars in a matplotlib bar chart?

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 13:01:06

5K+ Views

To determine the order of bars in a bar chart in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Add a subplot to the current figure.Make a bar plot with dataframe, df.Add a subplot to the current figure.Create another dataframe, df_sorted, by column marks.Make a bar plot with df_sorted.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame( ... Read More

Matplotlib – Date manipulation to show the year tick every 12 months

Rishikesh Kumar Rishi
Updated on 21-Sep-2021 11:34:04

3K+ Views

To make matplotlib date manipulation so that the year tick shows up every 12 months, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create d, y, s, years, months, monthsFmt and yearsFmt using Pandas, Numpy and matplotlib dates.Use "%B" in DateFormatter to show full month names.Ue "%Y" in DateFormatter to show years.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Plot "dts" and "s" data points using plot() method.Set minor or major axes locator and formatter. Set minor_locator as months ... Read More

How to make a scatter plot for clustering in Python?

Rishikesh Kumar Rishi
Updated on 19-Sep-2021 08:00:50

6K+ Views

To make a scatter plot for clustering in Python, 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, Cluster and centers using numpy.Create a new figure or activate an existing figure.Add a subplot arrangement to the current figure.Plot the scatter data points using scatter() method.Iterate centers data and place marker using scatter() method.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.randn(10) y = np.random.randn(10) Cluster = np.array([0, 1, ... Read More

How do I put a circle with annotation in matplotlib?

Rishikesh Kumar Rishi
Updated on 19-Sep-2021 07:28:03

2K+ Views

To put a circle with annotation in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create data points using numpy.Get the point coordinate to put circle with annotation.Get the current axis.Plot the data and data points using plot() method.Set X and Y axes scale.To put a circled marker, use the plot() method with marker='o' and some properties.Annotate that circle (Step 7) with arrow style.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.array([[5, ... Read More

Creating 3D animation using matplotlib

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 08:59:38

5K+ Views

To create a 3D animation using matplotlib, we can take the following steps −Import the required packages. For 3D animation, you need to import Axes3D from mpl_toolkits.mplot3d and matplotlib.animation.Set the figure size and adjust the padding between and around the subplots.Create t, x, y and data points using numpy.Create a new figure or activate an existing figure.Get the instance of 3D axes.Turn off the axes.Plot the lines with data.Create an animation by repeatedly calling a function *animate*.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from mpl_toolkits.mplot3d import Axes3D plt.rcParams["figure.figsize"] ... Read More

How to set labels in matplotlib.hlines?

Rishikesh Kumar Rishi
Updated on 19-Sep-2021 08:10:07

4K+ Views

To set labels in matplotlib.hlines, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Add a horizontal line across the axis, y=1, with y=1 label, color='orange'.Add a horizontal line across the axis, y=2, with y=2 label, color='red'.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Add horizontal line plt.hlines(y=1, xmin=1, xmax=4, lw=7, color='orange') plt.text(4, 1, 'y=1', ha='left', va='center') # Add another horizontal line plt.hlines(y=2, xmin=2, xmax=5, lw=7, color='red') plt.text(2, 2, 'y=2', ha='right', va='center') ... Read More

How to create broken horizontal bar graphs in matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 08:52:51

209 Views

To create broken horizontal bar graphs 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.Plot a horizontal sequence of rectangles.Scale X and Y axes limit.Configure the grid lines.Annotate the broken bars.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() # Horizontal sequence of rectangles ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='tab:blue') ax.broken_barh([(10, 50), (100, 20), (130, 10)], (20, 9),    facecolors=('tab:orange', 'tab:green', 'tab:red')) # Scale ... Read More

How to modify a 2d Scatterplot to display color based on a third array in a CSV file?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 08:47:24

238 Views

To modify a 2d scatterplot to display color based on a third array in a CSV file, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Read the CSV file with three headers.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Make a scatter plot with CSV file data points.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True columns = ["data1", "data2", "data3"] df = ... Read More

How to turn off the ticks and marks of a matlibplot axes?

Rishikesh Kumar Rishi
Updated on 10-Sep-2023 08:25:31

43K+ Views

To turn off the ticks and marks of a matplotlib axes, 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.Plot x and y data points using plot() method.Get the current axis of the plot.Use set_tick_params() to hide X and Y axes label marks.Use set_xticks() and set_yticks() to hide X and Y axes tick marks.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

Make a multiline plot from .CSV file in matplotlib

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 08:41:31

12K+ Views

To make a multiline plot from .CSV file in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of columns to fetch the data from a .CSV file. Make sure the names match with the column names used in the .CSV file.Read the data from the .CSV file.Plot the lines using df.plot() method.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Make a list of ... Read More

Advertisements