Matplotlib Articles

Page 2 of 91

How To Visualize Sparse Matrix in Python using Matplotlib?

Rohan Singh
Rohan Singh
Updated on 16-Oct-2023 2K+ Views

Sparse matrices are a specialized type of matrix that contain mostly zero values. These matrices are commonly encountered in applications such as graph theory, machine learning, and network analysis. Visualizing sparse matrices can provide valuable insights into the distribution and patterns of non-zero values. In this article, we will understand how to visualize sparse matrices in Python using the popular data visualization library, Matplotlib. Understanding Sparse Matrices A sparse matrix is a matrix in which most of the elements are zero. These matrices are typically large and inefficient to store in memory if all the zeros are explicitly represented. ...

Read More

Draw a Unstructured Triangular Grid as Lines or Markers in Python using Matplotlib

Utkarsha Nathani
Utkarsha Nathani
Updated on 11-Oct-2023 391 Views

Python is a popularly used programming language. It offers a wide range of tools and libraries which can be used for solving different problems, one of them is Matplotlib. This library provides various functions for data visualization and creating different plots. In this article, we will be using Matplotlib for drawing an unstructured triangular grid as liners or markers in python. What is Matplotlib and How to Install it? Matplotlib is one of the libraries of python. This library is very strong tool for serving the purpose of plotting graphs for visualizing data. It has a module named “pyplot” ...

Read More

How to Calculate and Plot the Derivative of a Function Using Python – Matplotlib?

Utkarsha Nathani
Utkarsha Nathani
Updated on 11-Oct-2023 5K+ Views

The Derivative of a function is one of the key concepts used in calculus. It is a measure of how much the function changes as we change the output. Whereas Matplotlib is a plotting library for python, since it does not provide a direct method to calculate the derivative of a function you need to use NumPy, which is also one of the python libraries and you can use it to calculate the derivative of a function and Matplotlib for visualizing the results. In this article, we will be calculating the derivative of a function using the NumPy ...

Read More

How to Change the Line Width of a Graph Plot in Matplotlib?

Utkarsha Nathani
Utkarsha Nathani
Updated on 11-Oct-2023 2K+ Views

Matplotlib one of the libraries of python, which plays an important role in beautifying plots and making the data analysis and data visualization an easier task. You can use Matplotlib for experimenting, by using different options available in it and creating a more appealing, informative plot. One common customization in Matplotlib is changing the line width of a graph plot. Since, line width controls the thickness of the lines, which are used in the plots at various points such as in connecting the plot points, etc. In this article, we will be learning how to change the line ...

Read More

How to change the color of the axis, ticks and labels for a plot in matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 07-Oct-2023 42K+ Views

We can change the color of the axis, ticks and labels, using ax.spines['left'].set_color('red') and ax.spines['top'].set_color('red') statements. To change the color of the axis, ticks, and labels for a plot in matplotlib, we can take the following steps −Create a new figure, or activate an existing figure, using plt.figure().Add an axis to the figure as part of a subplot arrangement, using plt.add_subplot(xyz) where x is nrows, y is ncols and z is the index. Here taking x = 1(rows), y = 2(columns) and z = 1(position).Set up X-axis and Y-axis labels using set_xlabel and set_ylabel method for creating ax using add_subplot().To ...

Read More

Data Pre-Processing with Sklearn using Standard and Minmax scaler

Someswar Pal
Someswar Pal
Updated on 05-Oct-2023 635 Views

Introduction Data pre-processing is required for producing trustworthy analytical results. Data preparation includes eliminating duplicates, identifying and fixing outliers, normalizing measurements, and filing away categories of information. Popular for its ability to scale features, handle missing data, and encode categorical variables, the Python-based Sklearn toolkit is an essential resource for pre-processing data. With Sklearn, preprocessing data is a breeze, and you have access to trustworthy methodologies for effective data analysis. Data Pre-Processing Techniques Standard Scaling Data can be transformed using standard scaling so that it is normally distributed around zero and one. It ensures that everything is uniform in size. This ...

Read More

How to write text in subscript in the axis labels and the legend using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Oct-2023 41K+ Views

To write text in subscript in the axis labels and the legend, we can take the following steps −Create x and y data points using NumPy.Plot x and y data points with a super subscript texts label.Use xlabel and ylabel with subscripts in the text.Use the legend() method to place a legend in the plot.Adjust the padding between and around subplots.To display the figure, use the show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 1000) y = np.exp(x) plt.plot(x, y, label=r'$e^x$', c="red", lw=2) plt.xlabel("$X_{axis}$") plt.ylabel("$Y_{axis}$") plt.legend(loc='upper left') plt.show()Output

Read More

How to clear the memory completely of all Matplotlib plots?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 14-Sep-2023 39K+ Views

Using the following methods, we can clear the memory occupied by Matplotlib plots.plt.figure() - Create a new figure or activate an existing figure.plt.figure().close() -  Close a figure window.close() by itself closes the current figureclose(h), where h is a Figure instance, closes that figureclose(num) closes the figure number, numclose(name), where name is a string, closes figure with that labelclose('all') closes all the figure windowsplt.figure().clear() - It is the same as clf.plt.cla() - Clear the current axes.plt.clf() - Clear the current figure.Examplefrom matplotlib import pyplot as plt fig = plt.figure() plt.figure().clear() plt.close() plt.cla() plt.clf()OutputWhen we execute the code, it will clear all the plots from ...

Read More

Plot a bar using matplotlib using a dictionary

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 14-Sep-2023 35K+ Views

First, we can define our dictionary and then, convert that dictionary into keys and values. Finally, we can use the data to plot a bar chart.StepsCreate a dictionary, i.e., data, where milk and water are the keys.Get the list of keys of the dictionary.Get the list of values of the dictionary.Plot the bar using plt.bar().Using plt.show(), show the figure.Exampleimport matplotlib.pyplot as plt data = {'milk': 60, 'water': 10} names = list(data.keys()) values = list(data.values()) plt.bar(range(len(data)), values, tick_label=names) plt.show()Output

Read More

Plot multiple boxplots in one graph in Pandas or Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 13-Sep-2023 36K+ Views

To plot multiple boxplots in one graph in Pandas or Matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas data frame with two columns.Plot the data frame using plot() method, with kind='boxplot'.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Pandas dataframe data = pd.DataFrame({"Box1": np.random.rand(10), "Box2": np.random.rand(10)}) # Plot the dataframe ax = data[['Box1', 'Box2']].plot(kind='box', title='boxplot') # Display ...

Read More
Showing 11–20 of 902 articles
« Prev 1 2 3 4 5 91 Next »
Advertisements