Articles on Trending Technologies

Technical articles with clear explanations and examples

How to make the Parula colormap in Matplotlib?

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

The Parula colormap is MATLAB's default colormap known for its perceptually uniform color transitions. In Matplotlib, we can create a custom Parula colormap using LinearSegmentedColormap with the official Parula color values. Creating the Parula Colormap We'll use the exact RGB values from MATLAB's Parula colormap to ensure authenticity − import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import LinearSegmentedColormap # Official Parula colormap RGB values parula_colors = [ (0.2081, 0.1663, 0.5292), (0.2116, 0.1898, 0.5777), (0.2123, 0.2138, 0.6270), ...

Read More

Setting the size of the plotting canvas in Matplotlib

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

To set the size of the plotting canvas in Matplotlib, you can control the figure dimensions using several approaches. The figure size determines how large your plot will appear when displayed or saved. Using rcParams (Global Setting) The most common approach is to set global parameters that affect all subsequent plots − import numpy as np import matplotlib.pyplot as plt # Set figure size globally plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create data points x = np.linspace(-2, 2, 100) y = np.sin(x) # Create the plot plt.plot(x, y) plt.title("Sine Wave with ...

Read More

What is the name of the default Seaborn color palette?

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

The default Seaborn color palette is called "deep". It consists of 10 distinct colors designed for categorical data visualization and provides good contrast between different categories. Getting the Default Color Palette You can retrieve and display the default Seaborn color palette using the following approach ? import seaborn as sns import matplotlib.pyplot as plt # Set figure size for better visualization plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Get the default color palette current_palette = sns.color_palette() # Display the palette as a horizontal array sns.palplot(current_palette) plt.title("Default Seaborn Color Palette: 'deep'") plt.show() ...

Read More

How to get different font sizes in the same annotation of Matplotlib?

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

To add different font sizes in the same annotation method, we can create multiple annotations with varying font sizes at different positions. This technique is useful for creating visually appealing text displays with hierarchical information. Step-by-Step Approach Make lists of x and y data points where text could be placed. Initialize a variable 'labels', i.e., a string. Make a list of sizes of the fonts. Use subplots() method to create a figure and a set of subplots. Iterate above lists and annotate each label's text and set its fontsize. To display the figure, use show() method. ...

Read More

How to load an image and show the image using Keras?

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

To load and display an image using Keras, we use the load_img() method from keras.preprocessing.image. This method loads an image file and allows us to set a target size for display. Steps Import the image module from keras.preprocessing Use load_img() method to load the image file Set the target size of the image using the target_size parameter Display the image using the show() method Syntax The basic syntax for loading an image is ? keras.preprocessing.image.load_img(path, target_size=None) Parameters path ? Path to the image file target_size ? Tuple of ...

Read More

Adjusting the spacing between the edge of the plot and the X-axis in Matplotlib

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

To adjust the spacing between the edge of the plot and the X-axis in Matplotlib, we can use several methods including tight_layout(), subplots_adjust(), or configure padding parameters. This is useful for preventing axis labels from being cut off or creating better visual spacing. Using tight_layout() Method The tight_layout() method automatically adjusts subplot parameters to give specified padding around the plot ? import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] x = np.linspace(-2, 2, 100) y = np.exp(x) plt.plot(x, y, c='red', lw=1) plt.tight_layout() plt.show() Using subplots_adjust() Method ...

Read More

How to add footnote under the X-axis using Matplotlib?

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

To add a footnote under the X-axis using Matplotlib, we can use the figtext() method to place text at specific coordinates on the figure. This is useful for adding citations, data sources, or explanatory notes. Using figtext() Method The figtext() method allows you to place text anywhere on the figure using normalized coordinates (0 to 1). Position (0, 0) is the bottom-left corner, and (1, 1) is the top-right corner. Example Here's how to add a footnote with a styled box under the X-axis − import numpy as np import matplotlib.pyplot as plt ...

Read More

Plot yscale class linear, log, logit and symlog by name in Matplotlib?

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

Matplotlib provides several Y-axis scaling options to better visualize data with different characteristics. The yscale() method allows you to apply linear, log, symlog, and logit scales by name to transform how data appears on the Y-axis. Setting Up the Data First, let's create sample data and configure the plot layout ? import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Generate sample data y = np.random.normal(loc=0.5, scale=0.4, size=1000) y = y[(y > 0) & (y < 1)] y.sort() x = np.arange(len(y)) print(f"Data range: {y.min():.3f} to {y.max():.3f}") ...

Read More

How to locate the median in a (Seaborn) KDE plot?

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

A Kernel Density Estimation (KDE) plot shows the probability density of data points. To locate and highlight the median in a Seaborn KDE plot, we can calculate the median value and draw a vertical line at that position. Steps to Add Median Line Create or load your dataset Calculate the median using np.median() Plot the KDE using sns.kdeplot() Add a vertical line at the median using plt.axvline() Example Here's how to create a KDE plot with the median highlighted − import numpy as np import seaborn as sns import matplotlib.pyplot as plt ...

Read More

How to set the margins of a Matplotlib figure?

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

To set the margins of a matplotlib figure, we can use the margins() method. This method controls the padding around the data in your plots, allowing you to adjust how much whitespace appears between the data and the plot boundaries. Syntax The margins() method accepts the following parameters: plt.margins(x=None, y=None, tight=None) x − Margin for the x-axis (default: 0.05) y − Margin for the y-axis (default: 0.05) tight − Whether to use tight layout (True/False) Example Here's how to create subplots with different margin settings ? import numpy ...

Read More
Showing 4531–4540 of 61,297 articles
« Prev 1 452 453 454 455 456 6130 Next »
Advertisements