Articles on Trending Technologies

Technical articles with clear explanations and examples

Showing points coordinate in a plot in Python Matplotlib

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

To show point coordinates in a plot in Python Matplotlib, we can use the annotate() method to add text labels at specific positions. This technique is useful for displaying exact coordinate values directly on the plot. Steps Set the figure size and adjust the padding between and around the subplots. Initialize a variable N and create x and y data points using NumPy. Plot the points using plot() method. Zip the x and y data points; iterate them and place coordinate annotations. Display the figure using show() method. Example import matplotlib.pyplot as plt ...

Read More

How to unset 'sharex' or 'sharey' from two axes in Matplotlib?

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

When creating multiple subplots in Matplotlib, you might want each subplot to have independent X and Y axes instead of sharing them. You can unset sharex and sharey by setting them to 'none' or False. Basic Syntax To create subplots without shared axes − fig, axes = plt.subplots(rows, cols, sharex='none', sharey='none') # or fig, axes = plt.subplots(rows, cols, sharex=False, sharey=False) Example with Independent Axes Let's create a 2x4 grid of subplots where each has independent X and Y axes − import matplotlib.pyplot as plt import numpy as np # Set ...

Read More

How to obtain 3D colored surface via Python?

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

To create a 3D colored surface plot in Python, we use matplotlib's 3D plotting capabilities with numpy for data generation. The surface colors are mapped based on z-values using colormaps. Steps to Create 3D Colored Surface Set the figure size and adjust the padding between and around the subplots. Create x and y data points using numpy. Generate 3D data (z values) based on x and y coordinates. Create a new figure or activate an existing figure. Get the 3D axes using ...

Read More

Scatter a 2D numpy array in matplotlib

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

Creating scatter plots from 2D NumPy arrays is a common visualization task in data analysis. Matplotlib's scatter() function can effectively plot multi-dimensional data using different columns for x, y coordinates, and colors. Basic Scatter Plot from 2D Array Let's start with a simple example using the first two columns of a 2D array ? import numpy as np import matplotlib.pyplot as plt # Create a 2D array with random data data = np.random.random((50, 3)) # Scatter plot using first two columns plt.figure(figsize=(8, 6)) plt.scatter(data[:, 0], data[:, 1]) plt.xlabel('X values (Column 0)') plt.ylabel('Y values (Column ...

Read More

How to avoid overlapping error bars in matplotlib?

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

When plotting multiple error bar series in matplotlib, overlapping error bars can make your visualization unclear and hard to read. You can avoid this by using affine transformations to shift the error bars horizontally. The Problem Without proper positioning, error bars from different data series overlap at the same x-coordinates, creating visual confusion ? Solution Using Affine2D Transforms Use Affine2D().translate() to shift error bars horizontally by small offsets ? import numpy as np import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Sample data names ...

Read More

How do I remove the Y-axis from a Pylab-generated picture?

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

To remove the Y-axis from a Pylab-generated picture, we can get the current axis of the plot and use the set_visible(False) method on the Y-axis. Steps Set the figure size and adjust the padding between and around the subplots. Create x and y data points using numpy. Plot the x and y data points using plot() method. Get the current axis of the current figure. Set the visibility to False for the Y-axis. To display the figure, use show() ...

Read More

Flushing all current figures in matplotlib

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

In matplotlib, you often create multiple figures during data visualization. To flush all current figures and free up memory, use the plt.close('all') method. Syntax plt.close('all') Creating Multiple Figures Let's first create multiple figures to demonstrate the flushing process ? import matplotlib.pyplot as plt import numpy as np # Configure figure settings plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create first figure plt.figure("First Figure") x1 = np.linspace(0, 10, 100) plt.plot(x1, np.sin(x1), 'b-') plt.title("Sine Wave") # Create second figure plt.figure("Second Figure") x2 = np.linspace(0, 10, 100) plt.plot(x2, np.cos(x2), ...

Read More

How to create multiple series scatter plots with connected points using seaborn?

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

Creating multiple series scatter plots with connected points in seaborn combines scatter plots with line connections to show relationships and trends across different data series. This visualization is useful for displaying how multiple variables change together over time or categories. Basic Setup First, let's import the required libraries and set up our data ? import pandas as pd import seaborn as sns import matplotlib.pyplot as plt # Set figure parameters plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create sample data with multiple series data = { 'x': [1, 2, ...

Read More

Combining two heatmaps in seaborn

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

Combining two heatmaps in seaborn allows you to display and compare related datasets side by side. This is useful for analyzing correlations, patterns, or differences between two datasets. Basic Approach To combine two heatmaps, we use matplotlib subplots and create separate heatmaps on each subplot. Here's the step-by-step process ? import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns # Set figure size plt.rcParams["figure.figsize"] = [10, 4] # Create sample datasets np.random.seed(42) df1 = pd.DataFrame(np.random.rand(8, 4), columns=["A", "B", "C", "D"]) df2 = pd.DataFrame(np.random.rand(8, 4), columns=["W", "X", "Y", ...

Read More

Boxplot stratified by column in Python Pandas

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

A boxplot stratified by column in Pandas allows you to create separate boxplots for different groups within your data. This is useful for comparing distributions across categorical variables. Basic Boxplot by Column Use the boxplot() method with the by parameter to group data ? import pandas as pd import matplotlib.pyplot as plt # Create sample data df = pd.DataFrame({ 'values': [23, 25, 28, 32, 35, 18, 22, 26, 30, 33], 'category': ['A', 'B', 'A', 'B', 'A', 'A', 'B', 'A', 'B', 'A'] }) print("Sample Data:") print(df) ...

Read More
Showing 2501–2510 of 61,297 articles
« Prev 1 249 250 251 252 253 6130 Next »
Advertisements