Data Visualization Articles

Page 17 of 68

How to extract only the month and day from a datetime object in Python?

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

To extract only the month and day from a datetime object in Python, you can use several approaches including the strftime() method, direct attribute access, or DateFormatter() for matplotlib plots. Using strftime() Method The strftime() method formats datetime objects into readable strings − from datetime import datetime # Create a datetime object dt = datetime(2023, 7, 15, 14, 30, 0) # Extract month and day using strftime() month_day = dt.strftime("%m-%d") print("Month-Day:", month_day) # With month name month_day_name = dt.strftime("%B %d") print("Month Day:", month_day_name) Month-Day: 07-15 Month Day: July 15 ...

Read More

How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 3K+ Views

When creating multiple subplots in Matplotlib, you might want to remove the first and last tick labels from the Y-axis to create cleaner visualizations. This can be achieved by iterating through the axes and setting specific tick labels to invisible. Method: Using setp() to Hide Tick Labels The most effective approach is to use plt.setp() to modify the visibility of specific tick labels ? import matplotlib.pyplot as plt import numpy as np # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create subplots with sample data fig, ax = ...

Read More

How to create a surface plot from a greyscale image with Matplotlib?

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

Creating a surface plot from a grayscale image with Matplotlib allows you to visualize image data in 3D, where pixel intensities become height values. This technique is useful for analyzing image textures, elevation maps, or any 2D data that benefits from 3D visualization. Basic Surface Plot from Grayscale Data Here's how to create a 3D surface plot using grayscale image data ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create sample grayscale image data (5x5 matrix) data = np.random.rand(5, 5) ...

Read More

How to draw a filled arc in Matplotlib?

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

To draw a filled arc in Matplotlib, you can use the fill_between() method combined with mathematical functions to create curved shapes. This technique is useful for creating semicircles, arcs, and other curved filled regions in your plots. Steps to Create a Filled Arc Set the figure size and adjust the padding between and around the subplots. Create a figure and a set of subplots. Initialize variables for radius and vertical offset. Create x and y data points using NumPy. Fill the area between x and y plots using fill_between(). Set the axis aspect ratio to "equal" for ...

Read More

How to display a sequence of images using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 3K+ Views

To display a sequence of images using Matplotlib, you can create an animated slideshow that cycles through multiple images. This technique is useful for comparing images, creating time-lapse visualizations, or building simple image presentations. Basic Image Sequence Display Here's how to display a sequence of images with automatic timing ? import matplotlib.pyplot as plt import numpy as np # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample images (since we can't load external files) def create_sample_image(color, text): """Create a sample colored image with ...

Read More

How to get multiple overlapping plots with independent scaling in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 3K+ Views

When creating visualizations with multiple data series that have different scales, you need overlapping plots with independent Y-axis scaling. Matplotlib's twinx() method allows you to create twin axes that share the same X-axis but have separate Y-axis scales. Basic Approach The key steps are ? Create the primary subplot with plt.subplots() Plot the first dataset on the primary Y-axis Create a twin axis using twinx() that shares the X-axis Plot the second dataset on the twin Y-axis Customize colors and labels for clarity Example import matplotlib.pyplot as plt # Set figure ...

Read More

How to increase the spacing between subplots in Matplotlib with subplot2grid?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 9K+ Views

To increase the spacing between subplots with subplot2grid, you can control the horizontal and vertical spacing using the wspace and hspace parameters. Here's how to create well-spaced subplots using GridSpec. Basic Approach The key steps are ? Set the figure size and adjust the padding between and around the subplots Create a grid layout using GridSpec to place subplots within a figure Update the subplot parameters with wspace and hspace for spacing control Add subplots to the current figure using subplot2grid or plt.subplot Display the figure using show() method Example with GridSpec ...

Read More

How to get an interactive plot of a pyplot when using PyCharm?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 3K+ Views

To get an interactive plot of a pyplot when using PyCharm, you need to configure the backend properly. PyCharm often defaults to inline backends that don't support interaction. By setting an interactive backend like Qt5Agg, you can enable zoom, pan, and other interactive features. Setting Up Interactive Backend The key is to use matplotlib.use() to set an interactive backend before importing pyplot ? import matplotlib as mpl # Set interactive backend before importing pyplot mpl.use('Qt5Agg') import matplotlib.pyplot as plt # Configure figure properties plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create ...

Read More

How to find the matplotlib style name?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 26-Mar-2026 261 Views

Matplotlib provides several built-in styles to customize the appearance of your plots. To find all available matplotlib style names, you can use the plt.style.library attribute which returns a dictionary containing all available styles and their configurations. Using plt.style.library The plt.style.library returns a dictionary where keys are style names and values are their complete configuration parameters ? import matplotlib.pyplot as plt print(plt.style.library) {'bmh': RcParams({'axes.edgecolor': '#bcbcbc', 'axes.facecolor': '#eeeeee', 'axes.grid': True, 'axes.labelsize': 'large', 'axes.prop_cycle': cycler('color', ['#348ABD', '#A60628', '#7A68A6', '#467821', '#D55E00', '#CC79A7', '#56B4E9', '#009E73', '#F0E442', '#0072B2']), ...

Read More

How to change the color and add grid lines to a Python Matplotlib surface plot?

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

To change the color and add grid lines to a Python Matplotlib surface plot, you can customize the plot_surface() method with color parameters and edge properties. This creates visually appealing 3D visualizations with clear grid patterns. Steps to Create a Colored Surface Plot with Grid Lines Import required libraries: numpy, matplotlib.pyplot, and Axes3D Set figure size and layout parameters Create coordinate arrays using numpy.meshgrid() Calculate height values for the surface Create 3D axes and plot surface with color and grid customization Example Here's how to create a surface plot with custom colors and visible ...

Read More
Showing 161–170 of 680 articles
« Prev 1 15 16 17 18 19 68 Next »
Advertisements