Articles on Trending Technologies

Technical articles with clear explanations and examples

How to get the list of axes for a figure in Pyplot?

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

In Matplotlib, you can retrieve all axes objects from a figure using the get_axes() method. This returns a list containing all axes in the figure, which is useful for programmatically manipulating multiple subplots. Basic Example with Single Axes Let's start with a simple example that creates a figure with one subplot and retrieves its axes ? import numpy as np import matplotlib.pyplot as plt # Create data xs = np.linspace(1, 10, 10) ys = np.tan(xs) # Create figure and add subplot fig = plt.figure(figsize=(8, 4)) ax = fig.add_subplot(111) # Get axes using get_axes() ...

Read More

Circular (polar) histogram in Python

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

A circular (polar) histogram displays data in a circular format using polar coordinates. This visualization is particularly useful for directional data like wind directions, angles, or cyclic patterns. Creating a Basic Polar Histogram To create a polar histogram, we need three main components: angles (theta), radii (heights), and bar widths. Here's how to create one ? import numpy as np import matplotlib.pyplot as plt # Set up data N = 20 theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False) radii = 10 * np.random.rand(N) width = np.pi / 4 * np.random.rand(N) # Create polar ...

Read More

How to add different graphs (as an inset) in another Python graph?

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

To add different graphs (as an inset) in another Python graph, we can use Matplotlib's add_axes() method to create a smaller subplot within the main plot. This technique is useful for showing detailed views or related data alongside the primary visualization. Steps to Create an Inset Graph Create x and y data points using NumPy Using subplots() method, create a figure and a set of subplots Add a new axis to the existing figure using add_axes() Plot data on both the main axis and the inset axis Use show() method to display the figure Basic ...

Read More

How to put text outside Python plots?

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

To put text outside a Python plot, you can control the text position by adjusting coordinates and using the transform parameter. The transform parameter determines the coordinate system used for positioning the text. Steps Create data points for x and y Initialize the text position coordinates Plot the data using plot() method Use text() method with transform=plt.gcf().transFigure to position text outside the plot area Display the figure using show() method Example Here's how to place text outside the plot ...

Read More

How to plot a confusion matrix with string axis rather than integer in Python?

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

A confusion matrix with string labels provides better readability than numeric indices. In Python, we can create such matrices using matplotlib and sklearn.metrics by customizing the axis labels with descriptive strings. Basic Setup First, let's import the required libraries and prepare sample data − import matplotlib.pyplot as plt from sklearn.metrics import confusion_matrix import numpy as np # Sample data - actual vs predicted classifications actual = ['business', 'health', 'business', 'tech', 'health', 'tech'] predicted = ['business', 'business', 'business', 'tech', 'health', 'business'] # Define string labels labels = ['business', 'health', 'tech'] print("Actual:", actual) print("Predicted:", predicted) print("Labels:", ...

Read More

Tkinter button commands with lambda in Python

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 33K+ Views

Lambda functions (also called anonymous functions) are very useful in Tkinter GUI applications. They allow us to pass arguments to callback functions when button events occur. In Tkinter button commands, lambda is used to create inline functions that can pass specific data to callback functions. Syntax The basic syntax for using lambda with Tkinter button commands is − button = Button(root, text="Click Me", command=lambda: function_name(arguments)) Example In this example, we will create an application with multiple buttons. Each button uses a lambda function to pass a specific value to a common callback function ...

Read More

How to create Tkinter buttons in a Python for loop?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 4K+ Views

Tkinter Button widgets are very useful for handling events and performing actions during application execution. We can create Tkinter Buttons using the Button(parent, text, options...) constructor. Using loops, we can efficiently create multiple buttons with minimal code. Basic Example with For Loop In this example, we will create multiple buttons using a Python for loop − import tkinter as tk from tkinter import ttk # Create main window root = tk.Tk() root.title("Multiple Buttons Example") root.geometry("400x300") # Create buttons using for loop for i in range(5): button = ttk.Button(root, text=f"Button {i}") ...

Read More

Why do we use import * and then ttk in TKinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 5K+ Views

In tkinter applications, we use from tkinter import * to import all tkinter functions and classes, making them directly accessible without prefixes. However, for themed widgets with modern styling, we need to separately import the ttk module. Understanding import * The import * syntax imports all public functions and classes from the tkinter module into the current namespace: from tkinter import * # Now you can use tkinter classes directly root = Tk() # Instead of tkinter.Tk() label = Label(root, text="Hello") # Instead of tkinter.Label() Why Import ttk Separately? The ...

Read More

What does calling Tk() actually do?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 9K+ Views

Tkinter is Python's built-in GUI library that provides functions and methods to create desktop applications. When you call Tk(), you create the root window − the main container that holds all other GUI components. This root window serves as the foundation of your tkinter application and manages the event loop that handles user interactions. What Happens When You Call Tk() When you execute Tk(), several important things occur behind the scenes ? Creates the main application window (root window) Initializes the Tk interpreter that communicates with the operating system Sets up the event handling system Establishes ...

Read More

What are the arguments to Tkinter variable trace method callbacks?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 5K+ Views

Tkinter variable trace method allows you to monitor changes to widget variables and execute callback functions when they occur. The callback function receives three specific arguments that provide context about the trace operation. Trace Method Arguments The callback function for trace_variable() receives three arguments ? var − The internal name of the variable being traced index − The index (for arrays) or empty string for scalar variables mode − The operation mode: "r" (read), "w" (write), or "u" (undefined) Example Here's how to trace an Entry widget and access all callback arguments ? ...

Read More
Showing 4841–4850 of 61,299 articles
« Prev 1 483 484 485 486 487 6130 Next »
Advertisements