Found 10476 Articles for Python

How to plot true/false or active/deactive data in Matplotlib?

Rishikesh Kumar Rishi
Updated on 15-Jun-2021 12:07:58

2K+ Views

To plot true/false or active/deactive data in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create data using numpy with True or False.Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Use imshow() method to display data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.random((20, 20)) > 0.5 fig = ... Read More

How to plot arbitrary markers on a Pandas data series using Matplotlib?

Rishikesh Kumar Rishi
Updated on 15-Jun-2021 11:46:37

437 Views

To plot arbitrary markers on a Pandas data series, we can use pyplot.plot() with markers.StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas data series with axis labels (including timeseries).Plot the series index using plot() method with linestyle="dotted".Use tick_params() method to rotate overlapping labels.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ts = pd.Series(np.random.randn(10), index=pd.date_range('2021-04-10', periods=10)) plt.plot(ts.index, ts, '*', ls='dotted', color='red') plt.tick_params(rotation=45) plt.show()OutputRead More

How to change the range of the X-axis and Y-axis in Matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Sep-2023 10:31:28

79K+ Views

To change the range of X and Y axes, we can use xlim() and ylim() methods.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using plot() method.Set the X and Y axes limit.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-15, 15, 100) y = np.sin(x) plt.plot(x, y) plt.xlim(-10, 10) plt.ylim(-1, 1) plt.show()Output

How to view all colormaps available in Matplotlib?

Rishikesh Kumar Rishi
Updated on 15-Jun-2021 12:06:49

177 Views

To view all colormaps available in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangementMake an axis that is divider on the existing axes.Create random data using numpy.Display the data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance, im.Set a title for the current figure.Animate the image with all colormaps available in matplotlib.Make an animation by repeatedly calling a function.To display the figure, ... Read More

What is Heap Sort in Python?

pawandeep
Updated on 11-Jun-2021 12:52:39

431 Views

Heap Sort is the sorting technique based on binary heap data structure. In order to proceed with heap sort, you need to be familiar with binary tree and binary heap.What is a Complete binary tree?A complete binary tree is a tree data structure where all the levels except the last one are completely filled. The last level must be filled from the left side.What is a Binary heap?Binary heap is a special case of the binary tree. Binary heaps are of two types −Max Heap − The parent node at each level is greater than its child nodes.Min Heap − ... Read More

Which is the fastest implementation of Python

pawandeep
Updated on 11-Jun-2021 12:51:50

922 Views

Python has many active implementations. We will be addressing its different implementations and know which is the fastest implementation.Different implementations of Python −IronPython − This is the Python implementation which runs on .NET framework. This implementation is written in C#. It uses .net virtual machine for running. IronPython can use the python libraries and .net framework libraries.Jython − Jython is the implementation of Python which runs on the Java Platform. The jython makes use of the java classes and libraries. The jythoncode is compiled into java byte code and it is run on Java Virtual Machine.PyPy − This is the implementation of Python ... Read More

What is Python Unit Testing?

pawandeep
Updated on 11-Jun-2021 12:51:30

699 Views

What is unit testing?Unit testing is a type of software testing where each individual component of the system is tested. Unit testing is important practice for the developers. It ensures that every component of the software is functioning appropriately as expected. Unit testing is mainly performed by the developers during the coding phase of the software development.Unit testing makes it easy to fix the problems as the developers come to know which particular component of the system or software has the issues and the developers can fix that particular unit.Python Unit TestingThe python has an in-built package called unittest which is ... Read More

How to read JSON file in Python

pawandeep
Updated on 23-Aug-2023 03:50:38

78K+ Views

What is a JSON file?JSON stands for JavaScript Object Notation. It is commonly used for transmitting data in web applications (such as sending data from server to client to display on the web pages).Sample JSON FileExample 1: {    "fruit": "Apple",    "size": "Large",    "color": "Red" }Example 2: {    'name': 'Karan',    'languages': ['English', 'French'] }The json file will have .json extensionRead JSON file in PythonPython has an in-built package called json which can be used to work with JSON data and to read JSON files. The json module has many functions among which load() and loads() are ... Read More

What is Insertion sort in Python?

pawandeep
Updated on 11-Jun-2021 12:50:08

6K+ Views

Insertion sort is the simple method of sorting an array. In this technique, the array is virtually split into the sorted and unsorted part. An element from unsorted part is picked and is placed at correct position in the sorted part.The array elements are traversed from 1 to n.If the array element at position i is greater than its predecessor, it does not need to be moved.If the array element at position i is less than its predecessor, it needs to be shifted towards left until we find a predecessor smaller than it or if we reach at the leftmost ... Read More

How to create a DataFrame in Python?

pawandeep
Updated on 25-Aug-2023 01:13:12

34K+ Views

Dataframe is a 2D data structure. Dataframe is used to represent data in tabular format in rows and columns. It is like a spreadsheet or a sql table. Dataframe is a Pandas object.To create a dataframe, we need to import pandas. Dataframe can be created using dataframe() function. The dataframe() takes one or two parameters. The first one is the data which is to be filled in the dataframe table. The data can be in form of list of lists or dictionary of lists. In case of list of lists data, the second parameter is the columns name.Create dataframe from ... Read More

Advertisements