Python Articles

Page 459 of 855

How to skip empty dates (weekends) in a financial Matplotlib Python graph?

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

When creating financial charts in Matplotlib, you often need to skip weekends (Saturday and Sunday) to display only business days. This prevents gaps in your time series visualization and provides a cleaner representation of trading data. Understanding Weekdays in Python Python's weekday() method returns integers where Monday=0, Tuesday=1, ..., Saturday=5, Sunday=6. To skip weekends, we check if weekday() returns 5 (Saturday) or 6 (Sunday). Basic Example Here's how to plot only weekdays while skipping weekends ? import pandas as pd import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [10, 6] plt.rcParams["figure.autolayout"] ...

Read More

How to write annotation outside the drawing in data coords in Matplotlib?

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

In Matplotlib, you can place annotations outside the plotting area using the annotate() method with specific coordinate systems. This is useful for adding titles, labels, or explanatory text that shouldn't interfere with your data visualization. Understanding Coordinate Systems Matplotlib offers different coordinate systems for positioning annotations ? Data coordinates: Based on your actual data values Axes coordinates: Relative to the axes (0-1 range) Transform coordinates: Using axis transforms for positioning outside plot area Basic Example with Transform Coordinates Here's how to place an annotation ...

Read More

Histogram for discrete values with Matplotlib

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

To plot a histogram for discrete values with Matplotlib, we can use the hist() method. Discrete histograms are useful for visualizing the frequency distribution of categorical or integer data points. Steps Set the figure size and adjust the padding between and around the subplots. Create a list of discrete values. Use hist() method to plot data with bins=length of data and edgecolor='black'. To display the figure, use show() method. Example Let's create a histogram for discrete values with proper bin configuration ? ...

Read More

Plotting only the upper/lower triangle of a heatmap in Matplotlib

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

To plot only the upper or lower triangle of a heatmap in Matplotlib, we can use NumPy to create a mask that hides specific parts of the data. This technique is useful for correlation matrices where the upper and lower triangles contain identical information. Plotting Lower Triangle Heatmap We use numpy.tri() to create a triangular mask and apply it to our data − 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 random 5x5 data data = np.random.rand(5, 5) # Create ...

Read More

Is it possible to control Matplotlib marker orientation?

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

To control matplotlib marker orientation, we can use marker tuples that contain the number of sides, style, and rotation angle of the marker. This technique is particularly useful for creating custom arrow-like markers or rotating polygonal shapes. Understanding Marker Tuples A marker tuple follows the format (numsides, style, angle) where − numsides − Number of sides for the polygon marker style − Style of the marker (0 for regular polygon) angle − Rotation angle in degrees Basic Example with Fixed Rotation Let's start with a simple example showing triangular markers with different orientations ...

Read More

How to change the linewidth of a hatch in Matplotlib?

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

To change the linewidth of a hatch in matplotlib, we can set the linewidth of the hatch using plt.rcParams['hatch.linewidth']. This parameter controls how thick or thin the hatch lines appear in your plots. Steps Set the figure size and adjust the padding between and around the subplots Create x and y=sin(x) data points using numpy Set the linewidth of the hatch using plt.rcParams['hatch.linewidth'] Plot x and y data points using scatter() method with a square marker having "/" hatches with set linewidth Display the figure using show() method Example Here's how to create a ...

Read More

Add a custom border to certain cells in a Matplotlib / Seaborn plot

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

Adding custom borders to specific cells in Matplotlib/Seaborn plots helps highlight important data points. You can use Rectangle patches to create colored borders around target cells in heatmaps. Basic Approach The process involves creating a heatmap, accessing its axes, and adding rectangle patches with custom colors and line widths ? import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # Create sample data data = pd.DataFrame({ "col1": [1, 4, 2, 3, 5], "col2": [3, 4, 1, 5, 2] }) # Create clustered ...

Read More

How do you just show the text label in a plot legend in Matplotlib?

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

When creating matplotlib plots with legends, you might want to display only the text labels without the colored lines or markers. This can be achieved using specific parameters in the legend() method to hide the legend handles. Basic Approach To show only text labels in a plot legend, use the legend() method with these key parameters: handlelength=0 − Sets the length of legend handles to zero handletextpad=0 − Removes padding between handle and text fancybox=False − Uses simple rectangular legend box Example Here's how to create a plot with text-only legend labels ? ...

Read More

Box plot with min, max, average and standard deviation in Matplotlib

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

A box plot is an effective way to visualize statistical measures like minimum, maximum, average, and standard deviation. Matplotlib combined with Pandas makes it easy to create box plots from calculated statistics. Creating Sample Data and Statistics First, let's create random data and calculate the required statistics − import numpy as np import pandas as pd from matplotlib import pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create random dataset of 5x5 dimension data = np.random.randn(5, 5) print("Sample data shape:", data.shape) print("First few rows:") print(data[:3]) ...

Read More

Adding a scatter of points to a boxplot using Matplotlib

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

To add a scatter of points to a boxplot using Matplotlib, we can combine the boxplot() method with scatter() to overlay individual data points. This technique helps visualize both the distribution summary and actual data points. Steps Set the figure size and adjust the padding between and around the subplots. Create a DataFrame using DataFrame class with sample data columns. Generate boxplots from the DataFrame using boxplot() method. Enumerate through DataFrame columns to get x and y coordinates for scatter points. Add scatter points with slight horizontal jitter for better visibility. Display the figure using show() method. ...

Read More
Showing 4581–4590 of 8,546 articles
« Prev 1 457 458 459 460 461 855 Next »
Advertisements