Articles on Trending Technologies

Technical articles with clear explanations and examples

How to hide the colorbar of a Seaborn heatmap?

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

To hide the colorbar of a Seaborn heatmap, we can use cbar=False in the heatmap() method. This is useful when you want to focus on the pattern visualization without showing the color scale legend. Basic Example Here's how to create a heatmap without a colorbar − import seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt # Set figure size plt.figure(figsize=(8, 6)) # Create sample data data = np.random.random((4, 4)) df = pd.DataFrame(data, columns=["A", "B", "C", "D"]) # Create heatmap without colorbar sns.heatmap(df, cbar=False, annot=True, fmt='.2f') ...

Read More

Setting active subplot using axes object in Matplotlib

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

To set an active subplot using axes objects in Matplotlib, you can use the plt.axes() function to switch between different subplot axes. This allows you to work with multiple subplots and control which one is currently active for plotting operations. Syntax fig, axs = plt.subplots(rows, cols) plt.axes(axs[index]) # Set specific subplot as active Basic Example Here's how to create subplots and switch between them using axes objects ? import matplotlib.pyplot as plt # Set figure configuration plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data x = ...

Read More

How to insert a scale bar in a map in Matplotlib?

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

To insert a scale bar in a map in matplotlib, we can use AnchoredSizeBar() class to instantiate the scalebar object. This is particularly useful for geographic visualizations where you need to show distance measurements. Steps Set the figure size and adjust the padding between and around the subplots. Create random data using numpy. Use imshow() method to display data as an image, i.e., on a 2D regular raster. Get the current axis using gca() method. Draw a horizontal scale bar with a center-aligned label underneath. Add a scalebar artist to the current axis. Turn off the axes. ...

Read More

How to plot gamma distribution with alpha and beta parameters in Python using Matplotlib?

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

The gamma distribution is a continuous probability distribution with two parameters: alpha (shape) and beta (scale). In Python, we can plot gamma distributions using scipy.stats.gamma.pdf() and Matplotlib to visualize how different parameter values affect the distribution shape. Steps Set the figure size and adjust the padding between and around the subplots. Create x values using numpy and y values using gamma.pdf() function. Plot x and y data points using plot() method. Use legend() method to place the legend elements for the plot. To display the figure, use show() method. Basic Gamma Distribution Plot Here's ...

Read More

How to change the font size of scientific notation in Matplotlib?

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

Scientific notation in Matplotlib can sometimes appear too small or too large for your plot. You can control the font size of scientific notation using various methods including rcParams, tick_params(), and direct axis formatting. Basic Scientific Notation with Default Font Size First, let's create a plot with scientific notation using default settings ? import matplotlib.pyplot as plt # Sample data with large values x = [10000, 20000, 300000, 34000, 50000, 100000] y = [1, 2, 3, 4, 5, 6] plt.figure(figsize=(8, 5)) plt.plot(x, y, color='red', marker='o') plt.ticklabel_format(axis="x", style="sci", scilimits=(0, 0)) plt.title("Default Scientific Notation") plt.show() ...

Read More

How do I plot hatched bars using Pandas and Matplotlib?

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

Hatched bars add visual texture and pattern to bar charts, making them more distinguishable and accessible. Using Pandas with Matplotlib, you can easily create hatched bar plots by setting hatch patterns on each bar patch. Basic Hatched Bar Plot Here's how to create a simple hatched bar chart ? import numpy as np import pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data df = pd.DataFrame(np.random.rand(5, 2), columns=['Series A', 'Series B']) ax = plt.figure().add_subplot(111) # Create bar plot bars = df.plot(ax=ax, kind='bar') # ...

Read More

How to show different colors for points and line in a Seaborn regplot?

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

Seaborn's regplot() allows you to customize the appearance of scatter points and regression lines separately. You can specify different colors using the scatter_kws and line_kws parameters. Basic Example with Different Colors Here's how to create a regression plot with red points and a green line ? import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample data np.random.seed(42) # For reproducible results df = pd.DataFrame({ "X-Axis": [np.random.randint(1, 6) for ...

Read More

How can I render 3D histograms in Python using Matplotlib?

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

A 3D histogram visualizes the frequency distribution of data in three-dimensional space using bars. Matplotlib's bar3d() method creates 3D bar plots that can represent histogram data with height, width, and depth dimensions. Basic 3D Histogram Here's how to create a basic 3D histogram using sample data ? import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Set figure size plt.rcParams["figure.figsize"] = [10, 8] plt.rcParams["figure.autolayout"] = True # Create figure and 3D subplot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Define positions and dimensions x_pos = [1, 2, 3, ...

Read More

Adding a legend to a Matplotlib boxplot with multiple plots on the same axis

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

When creating multiple boxplots on the same axis in Matplotlib, adding a legend helps distinguish between different datasets. This is particularly useful when comparing multiple groups or categories of data. Basic Boxplot with Legend First, let's create two datasets and plot them with different colors ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create sample datasets dataset_a = np.random.normal(10, 2, 100) dataset_b = np.random.normal(12, 3, 100) fig = plt.figure() ax = fig.add_subplot(111) # Create boxplots with different colors bp1 ...

Read More

How to draw an average line for a scatter plot in MatPlotLib?

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

To draw an average line for a scatter plot in matplotlib, you can overlay a horizontal line representing the mean value of your data. This is useful for visualizing how individual data points compare to the overall average. Basic Approach The key steps are ? Create your scatter plot with the original data points Calculate the average (mean) of your y-values Draw a horizontal line at the average y-value across the entire x-range Add a legend to distinguish between the data points and average line Example Here's how to create a scatter plot ...

Read More
Showing 4461–4470 of 61,297 articles
« Prev 1 445 446 447 448 449 6130 Next »
Advertisements