Data Visualization Articles

Page 53 of 68

How to make Matplotlib scatterplots transparent as a group?

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

To make matplotlib scatterplots transparent as a group, we can adjust the alpha parameter in the scatter() method. The alpha value controls transparency, where 0 is fully transparent and 1 is fully opaque. Basic Example with Two Groups Let's create two groups of scatter points with different transparency levels ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.figure(figsize=(8, 6)) # Create random data for two groups np.random.seed(42) # For reproducible results group1_x = np.random.normal(2, 0.8, 100) group1_y = np.random.normal(3, 0.8, 100) group2_x = np.random.normal(4, 0.8, 100) group2_y ...

Read More

How to decrease the density of x-ticks in Seaborn?

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

To decrease the density of x-ticks in Seaborn, we can control which tick labels are visible by using set_visible() method or by setting tick positions directly with matplotlib. Method 1: Using set_visible() for Alternate Ticks This approach hides every other tick label by iterating through tick labels and setting visibility based on index ? import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample dataframe df = pd.DataFrame({ "X-Axis": [i for i in range(10)], ...

Read More

What is the difference between plt.show and cv2.imshow in Matplotlib?

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

plt.show() and cv2.imshow() are two different methods for displaying images in Python. While plt.show() is part of Matplotlib and displays images in a Matplotlib figure window, cv2.imshow() is part of OpenCV and creates a native system window for image display. Key Differences Aspect plt.show() cv2.imshow() Library Matplotlib OpenCV Color Format RGB BGR Window Type Matplotlib figure Native system window Multiple Images Subplots supported Separate windows Using plt.show() with Matplotlib Matplotlib displays images in RGB format and provides rich plotting capabilities − import ...

Read More

Map values to colors in Matplotlib

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

To map values to colors (red, green, and blue) in Matplotlib, you can use the colormap and normalization features. This technique is useful for creating custom color schemes based on data values. Basic Color Mapping Here's how to map numerical values to RGB color tuples ? import numpy as np from matplotlib import cm, colors # Create values from 1.0 to 2.0 values = np.linspace(1.0, 2.0, 10) # Normalize data to [0, 1] range norm = colors.Normalize(vmin=1.0, vmax=2.0, clip=True) # Create color mapper using grayscale colormap mapper = cm.ScalarMappable(norm=norm, cmap=cm.Greys_r) # Map ...

Read More

Drawing a network graph with networkX and Matplotlib

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

NetworkX is a Python library for creating, manipulating, and studying complex networks. Combined with Matplotlib, it provides powerful visualization capabilities for drawing network graphs with customizable node and edge properties. Basic Network Graph Creation To create a simple network graph, we first need to prepare our data and then use NetworkX to build the graph structure ? import pandas as pd import networkx as nx import matplotlib.pyplot as plt # Set figure size for better visualization plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] = True # Create a DataFrame with edge connections df = pd.DataFrame({ ...

Read More

How do you draw R-style axis ticks that point outward from the axes in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 284 Views

To draw R-style axis ticks that point outward from the axes in Matplotlib, we can use rcParams to control tick direction. By default, Matplotlib draws ticks inward, but R-style plots typically have outward-pointing ticks. Setting Outward Tick Direction Use plt.rcParams to configure tick direction globally ? import numpy as np import matplotlib.pyplot as plt # Set outward tick direction for both axes plt.rcParams['xtick.direction'] = 'out' plt.rcParams['ytick.direction'] = 'out' # Create sample data n = 10 x = np.linspace(-2, 2, n) y = np.exp(x) # Create the plot plt.figure(figsize=(8, 5)) plt.plot(x, y, 'b-', marker='o', ...

Read More

How do I convert (or scale) axis values and redefine the tick frequency in Matplotlib?

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

In Matplotlib, you can convert or scale axis values and redefine tick frequency using the xticks() and yticks() methods. This allows you to customize how your axis labels appear and control the spacing between tick marks. Basic Axis Scaling and Tick Customization Here's how to create custom axis scales and redefine tick frequency ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.figure(figsize=(10, 6)) # Create data n = 10 x = np.linspace(-2, 2, n) y = np.exp(x) # Plot the data plt.plot(x, y, marker='o') # Create custom ...

Read More

Python Scatter Plot with Multiple Y values for each X

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

A scatter plot with multiple Y values for each X is useful when you have several data points that share the same X coordinate but have different Y values. This creates vertical clusters of points along specific X positions. Understanding Multiple Y Values per X When we say "multiple Y values for each X, " we mean having several data points with the same X coordinate but different Y coordinates. This creates vertical groupings in your scatter plot. Method 1: Using Zip with Random Data The simplest approach is to create paired X and Y values ...

Read More

What does axes.flat in Matplotlib do?

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

The axes.flat property in Matplotlib provides a 1D iterator over a 2D array of subplots. This is particularly useful when you have multiple subplots arranged in rows and columns, and you want to iterate through them sequentially without worrying about their 2D structure. Understanding axes.flat When you create subplots using plt.subplots(nrows, ncols), the returned axes object is a 2D NumPy array. The axes.flat property flattens this 2D array into a 1D iterator, making it easier to loop through all subplots ? Basic Example Here's how to use axes.flat to plot the same data across multiple subplots ...

Read More

How to write text above the bars on a bar plot (Python Matplotlib)?

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

Adding text labels above bars in a matplotlib bar plot helps display exact values for better data interpretation. We can achieve this using the text() method to position labels at the top of each bar. Basic Setup First, let's create a simple bar plot with population data across different years − import matplotlib.pyplot as plt import numpy as np # Sample data years = [1901, 1911, 1921, 1931, 1941, 1951, 1961, 1971, 1981, 1991, 2001, 2011] population = [237.4, 238.4, 252.09, 251.31, 278.98, 318.66, 361.09, ...

Read More
Showing 521–530 of 680 articles
« Prev 1 51 52 53 54 55 68 Next »
Advertisements