Server Side Programming Articles

Page 361 of 2109

Programmatically Stop Interaction for specific Figure in Jupyter notebook

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

To programmatically stop interaction for specific figures in Jupyter notebook, we can use plt.ioff() to turn off interactive mode. This prevents figures from automatically displaying when created or modified. Understanding Interactive Mode By default, matplotlib in Jupyter notebooks runs in interactive mode. When interactive mode is on, plots are displayed immediately. Using plt.ioff() turns off this behavior, giving you control over when figures are displayed. Step-by-Step Process Follow these steps to control figure interaction ? Enable matplotlib backend with %matplotlib auto Import matplotlib and configure figure settings Create your plot normally Use plt.ioff() to ...

Read More

How to animate 3D plot_surface in Matplotlib?

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

To animate 3D plot_surface in Matplotlib, we can create dynamic surface plots that change over time. This technique is useful for visualizing time-dependent data or mathematical functions that evolve. Key Components The animation requires several key components ? Initialize variables for number of mesh grids (N), frequency per second (fps), and frame numbers (frn) Create x, y and z arrays for the surface mesh Make a function to generate z-array values for each frame Define an update function that removes the previous plot and creates a new surface Use FuncAnimation to orchestrate the animation ...

Read More

How to combine several matplotlib axes subplots into one figure?

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

To combine several matplotlib axes subplots into one figure, we can use subplots() method with nrows parameter to create multiple subplot arrangements in a single figure. Steps Set the figure size and adjust the padding between and around the subplots Create x, y1 and y2 data points using numpy Create a figure and a set of subplots using subplots() method Plot x, y1 and y2 data points using plot() method To display the figure, use show() method Example − Vertical Subplots Here's how to create two subplots arranged vertically ? import numpy ...

Read More

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 622 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
Showing 3601–3610 of 21,090 articles
« Prev 1 359 360 361 362 363 2109 Next »
Advertisements