Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 411 of 2109
Scatter plot and Color mapping in Python
We can create scatter plots with color mapping using Matplotlib's scatter() method. This technique allows us to visualize an additional dimension of data through color variations, making patterns and relationships more apparent. Basic Scatter Plot with Color Mapping Here's how to create a scatter plot where each point has a different color based on its position in the dataset − import matplotlib.pyplot as plt import numpy as np # Generate random data points x = np.random.rand(100) y = np.random.rand(100) # Create scatter plot with color mapping colors = range(100) plt.scatter(x, y, c=colors, cmap='viridis') plt.colorbar() ...
Read MoreHow to reset index in Pandas dataframe?
In Pandas, the index serves as row labels for a DataFrame. Sometimes you need to reset the index back to the default integer sequence (0, 1, 2...) or convert a custom index into a regular column. The reset_index() method provides this functionality. Basic reset_index() Usage Let's start with a simple example showing how to reset a DataFrame's index ? import pandas as pd # Create DataFrame with default index data = {'Name': ["Allen", "Jack", "Mark", "Vishal"], 'Marks': [85, 92, 99, 87]} df = pd.DataFrame(data) print("Original DataFrame:") ...
Read MoreHow to plot two dotted lines and set marker using Matplotlib?
In this article, we will learn how to plot two dotted lines with custom markers using Matplotlib. Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Prerequisites First, we need to import the matplotlib.pyplot module ? import matplotlib.pyplot as plt Pyplot is a collection of command-style functions that make matplotlib work like MATLAB, providing an easy interface for plotting. Basic Example with Dotted Lines Let's start with a simple example plotting two dotted lines ? import matplotlib.pyplot as plt # Define coordinates for two ...
Read MoreHow to draw different shapes using the Python Turtle library?
The Python Turtle library provides a fun way to create graphics by controlling a turtle that moves around a drawing canvas. In this tutorial, we'll learn how to draw different geometric shapes including squares, rectangles, circles, and hexagons using turtle graphics. What is Turtle Graphics? Turtle graphics is a drawing method where you control a "turtle" that moves around the screen, leaving a trail behind it. You can command the turtle to move forward, turn left or right, and lift or lower its pen to create various shapes and patterns. Drawing a Square A square has ...
Read MorePython program to compare two Pandas series
In this program, we will declare two Pandas series and compare their elements using comparison operators. Pandas provides element-wise comparison operations that return boolean Series objects. Before we solve the problem, we need to import the Pandas library into our local IDE. This can be done by installing Pandas on our local machine. The command for installing Pandas is − pip install pandas Input Data We will use two sample series for comparison ? Series1 = [2, 4, 6, 8, 10] Series2 = [1, 3, 5, 7, 9] Algorithm ...
Read MoreHow to maximize a plt.show() window using Python?
To maximize a matplotlib plot window, you can use the figure manager's built-in methods. The most common approach is using plt.get_current_fig_manager() along with full_screen_toggle() or window.state() methods. Method 1: Using full_screen_toggle() This method toggles the window to full screen mode ? import matplotlib.pyplot as plt plt.subplot(1, 1, 1) plt.pie([1, 2, 3], labels=['A', 'B', 'C']) plt.title('Sample Pie Chart') mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show() Method 2: Using window.state() (Tkinter backend) For Tkinter backend, you can maximize the window using the state method ? import matplotlib.pyplot as plt plt.subplot(1, 1, 1) ...
Read MoreHow to make two plots side-by-side using Python?
When creating data visualizations, you often need to display multiple plots side-by-side for comparison. Python's Matplotlib provides the subplot() method to divide a figure into multiple sections and place plots in specific positions. Using plt.subplot() Method The subplot(nrows, ncols, index) method splits a figure into a grid of nrows × ncols sections. The index parameter specifies which section to use for the current plot ? from matplotlib import pyplot as plt import numpy as np # Create sample data x_points = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) y1_points = np.array([12, 14, ...
Read MoreSaving images in Python at a very high quality
To save images in Python with very high quality, you need to control the image format and resolution. The most effective approach is using matplotlib's savefig() method with optimized parameters. Steps for High-Quality Image Saving Create fig and ax variables using subplots() method, where default nrows and ncols are 1. Plot the data using plot() method. Add axes labels using ylabel() and xlabel(). Use vector formats like .eps, .pdf, or .svg for scalable quality. Increase the DPI (dots per inch) value for ...
Read MorePython program to remove duplicate elements from a Circular Linked List
When it is required to remove duplicates from a circular linked list, a Node class needs to be created. In this class, there are two attributes: the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have NULL value in the last node. Another class needs to be created that would have an initialization function, and the head of the node would be initialized to ...
Read MorePython program to insert a new node at the middle of the Circular Linked List
When it is required to insert a new node at the middle of the circular linked list, a Node class needs to be created. In this class, there are two attributes: the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node. Instead, the last node points back to the first node. Node Class Structure The Node class ...
Read More