Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create a Swarm Plot with Matplotlib?

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

A swarm plot is a categorical scatter plot that shows the distribution of data points without overlap. In Python, we can create swarm plots using Seaborn library, which provides better categorical plotting capabilities than Matplotlib alone. Basic Swarm Plot Let's start with a simple swarm plot using Seaborn ? import seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [8, 5] plt.rcParams["figure.autolayout"] = True # Create sample data data = pd.DataFrame({ "Category": ["A", "A", "A", "B", "B", "B", ...

Read More

How to display the matrix value and colormap in Matplotlib?

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

To display matrix values with a colormap in Matplotlib, you can use matshow() to create a color-coded visualization and overlay text annotations. This technique is useful for visualizing correlation matrices, confusion matrices, or any 2D data arrays. Basic Matrix Display with Values Here's how to create a matrix visualization with both colors and text values ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and subplot fig, ax = plt.subplots() # Create a sample matrix min_val, max_val = 0, ...

Read More

How to annotate a range of the X-axis in Matplotlib?

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

Annotating a range of the X-axis in Matplotlib helps highlight specific sections of your data. This is useful for marking important intervals, peaks, or regions of interest in your plots. Basic Range Annotation Use annotate() with arrow properties to create a visual range indicator ? import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create data points xx = np.linspace(0, 10) yy = np.sin(xx) fig, ax = plt.subplots(1, 1) ax.plot(xx, yy) ax.set_ylim([-2, 2]) # Annotate range with arrow ax.annotate('', xy=(5, 1.5), xytext=(8, 1.5), ...

Read More

How to annotate several points with one text in Matplotlib?

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

Matplotlib provides the annotate() method to add text labels to specific points on a plot. This is useful for highlighting important data points or providing additional context to your visualizations. Basic Annotation Example Let's start with a simple example of annotating multiple points on a scatter plot ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.figure(figsize=(8, 6)) # Create sample data x_points = np.array([1, 3, 5, 7, 9]) y_points = np.array([2, 8, 3, 9, 5]) # Create labels for each point labels = ['Point A', 'Point B', 'Point ...

Read More

How to plot a line in Matplotlib with an interval at each data point?

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

To plot a line in Matplotlib with confidence intervals or error bars at each data point, we can use the fill_between() method to create a shaded region around the main line. This technique is commonly used to show uncertainty or variability in data visualization. Basic Setup First, let's understand the key steps involved ? Create arrays for means and standard deviations Plot the main line using plot() method Use fill_between() to create shaded intervals Customize appearance with colors and transparency Example Here's how to create a line plot with confidence intervals ? ...

Read More

How to plot CSV data using Matplotlib and Pandas in Python?

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

To plot CSV data using Matplotlib and Pandas in Python, we can read CSV files directly into a DataFrame and create visualizations. This approach combines the data manipulation power of Pandas with Matplotlib's plotting capabilities. Creating Sample CSV Data First, let's create a sample CSV file to demonstrate the plotting process ? import pandas as pd import matplotlib.pyplot as plt # Create sample data data = { 'Name': ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'], 'Age': [23, 25, 22, 24, 26], 'Marks': [85, 92, 78, ...

Read More

How to create a line chart using Matplotlib?

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

A line chart is one of the most common data visualization techniques used to display trends over time. Matplotlib provides the plot() function to create line charts with customizable styles and markers. Basic Steps to Create a Line Chart To create a line chart using matplotlib, follow these steps − Import the matplotlib.pyplot module Set the figure size and adjust the padding between subplots Prepare your data as lists or arrays Plot the data using plot() method Display the figure using show() method Example Let's create a line chart showing population growth over ...

Read More

How to use different markers for different points in a Pylab scatter plot(Matplotlib)?

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

To use different markers for different points in a Pylab (Pyplot) scatter plot, you can assign unique markers to each data point. This technique is useful for distinguishing between different categories or highlighting specific points in your visualization. Basic Approach The key steps are ? Set the figure size and adjust the padding between and around the subplots Initialize variables for sample data Create x and y data points Make a list of different markers Zip the coordinates with markers and plot each point individually Display the figure using show() method Example Here's ...

Read More

How to show an image in Matplotlib in different colors with different channels?

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

Matplotlib allows you to visualize different color channels of an image by applying specific colormaps to highlight Red, Green, and Blue components separately. This technique is useful for analyzing color distribution and understanding how each channel contributes to the final image. Basic Setup and Image Loading First, let's create a simple image array to demonstrate channel visualization ? import matplotlib.pyplot as plt import numpy as np # Create a sample RGB image (50x50 pixels) image = np.random.rand(50, 50, 3) # Set figure parameters plt.rcParams["figure.figsize"] = [12, 4] plt.rcParams["figure.autolayout"] = True print(f"Image shape: {image.shape}") ...

Read More

How to add a second X-axis at the bottom of the first one in Matplotlib?

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

In Matplotlib, you can add a second X-axis at the top of your plot using the twiny() method. This creates a twin axis that shares the same Y-axis but has an independent X-axis positioned at the top. Steps Set the figure size and adjust the padding between and around the subplots Get the current axis (ax1) using gca() method Create a twin axis (ax2) sharing the Y-axis using twiny() Set X-axis ticks and labels for both axes Display the figure using show() method Example Here's how to create a plot with two X-axes − ...

Read More
Showing 4091–4100 of 61,297 articles
« Prev 1 408 409 410 411 412 6130 Next »
Advertisements