Programming Articles

Page 365 of 2547

How to get XKCD font working in Matplotlib?

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

To get XKCD font working in Matplotlib, we can use plt.xkcd() to turn on sketch-style drawing mode. This creates hand-drawn style plots similar to the popular XKCD webcomic. Steps Set the figure size and adjust the padding between and around the subplots Create x and y data points using numpy Use plt.xkcd() to turn on sketch-style drawing mode Create a new figure or activate an existing figure Add an axis to the figure as part of a subplot arrangement Plot x and y data points using plot() method Place text and title on the plot To display ...

Read More

How to make colorbar orientation horizontal in Python using Matplotlib?

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

In Matplotlib, colorbars are displayed vertically by default. To create a horizontal colorbar, use the orientation="horizontal" parameter in the colorbar() method. Basic Syntax plt.colorbar(mappable, orientation="horizontal") Example Let's create a scatter plot with a horizontal colorbar ? 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 # Generate random data points x, y, z = np.random.rand(3, 50) # Create figure and subplot f, ax = plt.subplots() # Create scatter plot with color mapping points = ax.scatter(x, y, c=z, s=50, ...

Read More

How to plot an array in Python using Matplotlib?

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

To plot an array in Python, we use Matplotlib, a powerful plotting library. This tutorial shows how to create line plots from NumPy arrays with proper formatting and styling. Basic Array Plotting Here's how to plot a simple array using Matplotlib ? import numpy as np import matplotlib.pyplot as plt # Create arrays x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 1, 5, 3]) # Create the plot plt.figure(figsize=(8, 5)) plt.plot(x, y, color="red", marker='o') plt.title("Basic Array Plot") plt.xlabel("X values") plt.ylabel("Y values") plt.grid(True, alpha=0.3) plt.show() Single Array Plotting When ...

Read More

Creating curved edges with NetworkX in Python3 (Matplotlib)

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

Creating curved edges in NetworkX graphs enhances visual clarity when multiple edges exist between nodes. The connectionstyle parameter with arc3 creates smooth curved connections instead of straight lines. Steps to Create Curved Edges Import required libraries (NetworkX and Matplotlib) Configure figure settings for optimal display Create a directed graph object Add nodes and edges to the graph Use connectionstyle="arc3, rad=0.4" in the draw function Display the graph with curved edges Example Here's how to create a directed graph with curved edges ? import matplotlib.pyplot as plt import networkx as nx # ...

Read More

How to Create a Diverging Stacked Bar Chart in Matplotlib?

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

A diverging stacked bar chart displays data that can extend both above and below a baseline (usually zero). This visualization is useful for comparing positive and negative values across categories, such as survey responses, profit/loss data, or demographic comparisons. Understanding Diverging Stacked Bar Charts In a diverging stacked bar chart, bars can extend in both directions from a central baseline. The key is using both positive and negative values to create the diverging effect, with stacked segments building upon each other. Creating a Basic Diverging Stacked Bar Chart Here's how to create a diverging stacked bar ...

Read More

How to use Matplotlib to plot PySpark SQL results?

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

To use Matplotlib to plot PySpark SQL results, we need to convert Spark DataFrames to Pandas DataFrames and then use Matplotlib for visualization. This process involves setting up a Spark context, creating a DataFrame, running SQL queries, and converting results for plotting. Setting Up the Environment First, we need to import the required libraries and configure Matplotlib ? from pyspark.sql import SparkSession, Row import matplotlib.pyplot as plt # Configure matplotlib plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create Spark session spark = SparkSession.builder.appName("MatplotlibExample").getOrCreate() Creating Sample Data and DataFrame We'll create ...

Read More

How to manipulate figures while a script is running in Python Matplotlib?

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

Manipulating figures while a script is running allows you to create dynamic, animated plots that update in real-time. This is useful for visualizing data streams, creating interactive demonstrations, or building animated visualizations. Basic Figure Manipulation To manipulate figures during script execution, you need to create a figure, display it, and then update it using canvas.draw() and plt.pause() ? import numpy as np import matplotlib.pyplot as plt # Set figure size and layout plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and get current axis fig = plt.figure() ax = fig.gca() fig.show() ...

Read More

How to plot a kernel density plot of dates in Pandas using Matplotlib?

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

A kernel density plot visualizes the probability density function of data. When working with dates in Pandas, we need to convert them to numerical values before plotting the density estimate. Steps to Create a Kernel Density Plot Create a DataFrame with date values Convert dates to ordinal numbers for numerical processing Plot the kernel density estimate using plot(kind='kde') Format x-axis ticks back to readable date labels Example Here's how to create a kernel density plot for date data ? import pandas as pd import numpy as np import datetime import matplotlib.pyplot as ...

Read More

How can I get the length of a single unit on an axis in Matplotlib?

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

To get the length of a single unit on an axis in Matplotlib, you need to use the transData transform to convert data coordinates to display coordinates. This helps determine how many pixels represent one unit on each axis. Understanding the Transform Method The transData transform converts data coordinates to display (pixel) coordinates. By transforming unit vectors and comparing them to the origin, we can calculate the pixel length of a single unit on each axis. Example Here's how to calculate the length of a single unit on both axes ? import numpy as ...

Read More

How do I redraw an image using Python's Matplotlib?

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

To redraw an image using Python's Matplotlib, you can dynamically update plots by clearing and redrawing content. This is useful for creating animations or real-time data visualization. Basic Steps for Redrawing The process involves these key steps: Set the figure size and adjust the padding between and around the subplots Create a new figure or activate an existing figure Get the current axis using gca() method Show the current figure Iterate and redraw the plot with new data ...

Read More
Showing 3641–3650 of 25,466 articles
« Prev 1 363 364 365 366 367 2547 Next »
Advertisements