Matplotlib Articles

Page 65 of 91

Extract csv file specific columns to list in Python

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 16K+ Views

To extract specific columns from a CSV file into a list in Python, we can use Pandas read_csv() method with the usecols parameter. This allows us to select only the columns we need, making our data processing more efficient. Steps to Extract Specific Columns Create a list of column names that need to be extracted Use read_csv() method with usecols parameter to extract specific columns Convert the extracted columns to lists if needed Process or visualize the extracted data Basic Column Extraction ...

Read More

How to make a log histogram in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 4K+ Views

To make a log histogram in Python, we can use log=True in the argument of the hist() method. This creates a histogram where the y-axis is displayed on a logarithmic scale, which is useful for data with wide ranges or exponential distributions. What is a Log Histogram? A log histogram displays the frequency counts on a logarithmic scale instead of a linear scale. This is particularly useful when your data spans several orders of magnitude or when you want to visualize the distribution of exponentially distributed data more clearly. Basic Log Histogram Here's how to create ...

Read More

How can I display an image using cv2 in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 1K+ Views

To display an image using cv2 in Python, we need to follow a sequence of steps: load the image, display it in a window, wait for user input, and clean up the resources. Steps to Display an Image Load an image from a file using cv2.imread() Display the image in a specified window using cv2.imshow() Wait for a key press using cv2.waitKey() Destroy all HighGUI windows using cv2.destroyAllWindows() Example Here's a complete example that demonstrates how to display an image ? ...

Read More

Save figure as file from iPython notebook using Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 5K+ Views

To save a figure as a file from iPython notebook using Matplotlib, we can use the savefig() method. This method allows you to export plots in various formats like PNG, PDF, SVG, and more. Basic Steps To save a figure as a file from iPython, we can take the following steps − Create a new figure or activate an existing figure Add an axes to the figure using add_axes() method Plot the data Save the plot using savefig() method Example Here's ...

Read More

Matplotlib – Plot over an image background in Python

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 20K+ Views

To plot over an image background in Matplotlib, you can overlay plots on top of images using imshow() and standard plotting functions. This technique is useful for data visualization on maps, annotating images, or creating custom backgrounds for plots. Steps to Plot Over an Image Read an image from a file into an array using plt.imread() Create a figure and subplot with plt.subplots() Display the image using imshow() with specified extent Create your plot data and overlay it using standard plotting methods Display the final result with plt.show() Example Here's how to create a ...

Read More

How to specify values on Y-axis in Python Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 13K+ Views

In Matplotlib, you can customize the Y-axis values using the yticks() method to specify both the positions and labels of the ticks. This is useful when you want to replace numeric values with descriptive labels or control exactly which values appear on the axis. Basic Y-axis Customization The yticks() method allows you to specify tick positions and their corresponding labels − import numpy as np import matplotlib.pyplot as plt # Create sample data x = np.array([0, 2, 4, 6]) y = np.array([1, 3, 5, 7]) # Create custom labels for both axes ticks = ...

Read More

Matplotlib – How to insert a degree symbol into a Python plot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 12K+ Views

To insert a degree symbol into a Python plot, you can use LaTeX representation with the syntax $^\circ$. This is particularly useful when plotting temperature data or angular measurements. Steps Create data points for pV, nR and T using numpy Plot pV and T using plot() method Set xlabel for pV using xlabel() method Set the label for temperature with degree symbol using ylabel() method To display the figure, use show() method Example Let's create a simple temperature vs ...

Read More

How to get the list of axes for a figure in Pyplot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 6K+ Views

In Matplotlib, you can retrieve all axes objects from a figure using the get_axes() method. This returns a list containing all axes in the figure, which is useful for programmatically manipulating multiple subplots. Basic Example with Single Axes Let's start with a simple example that creates a figure with one subplot and retrieves its axes ? import numpy as np import matplotlib.pyplot as plt # Create data xs = np.linspace(1, 10, 10) ys = np.tan(xs) # Create figure and add subplot fig = plt.figure(figsize=(8, 4)) ax = fig.add_subplot(111) # Get axes using get_axes() ...

Read More

Circular (polar) histogram in Python

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 2K+ Views

A circular (polar) histogram displays data in a circular format using polar coordinates. This visualization is particularly useful for directional data like wind directions, angles, or cyclic patterns. Creating a Basic Polar Histogram To create a polar histogram, we need three main components: angles (theta), radii (heights), and bar widths. Here's how to create one ? import numpy as np import matplotlib.pyplot as plt # Set up data N = 20 theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False) radii = 10 * np.random.rand(N) width = np.pi / 4 * np.random.rand(N) # Create polar ...

Read More

How to add different graphs (as an inset) in another Python graph?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 1K+ Views

To add different graphs (as an inset) in another Python graph, we can use Matplotlib's add_axes() method to create a smaller subplot within the main plot. This technique is useful for showing detailed views or related data alongside the primary visualization. Steps to Create an Inset Graph Create x and y data points using NumPy Using subplots() method, create a figure and a set of subplots Add a new axis to the existing figure using add_axes() Plot data on both the main axis and the inset axis Use show() method to display the figure Basic ...

Read More
Showing 641–650 of 902 articles
« Prev 1 63 64 65 66 67 91 Next »
Advertisements