- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1034 Articles for Matplotlib
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To plot multiple line graphs using Pandas and Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a 2D potentially heterogeneous tabular data using Pandas DataFrame class, where the column are x, y and equation.Get the reshaped dataframe organized by the given index such as x, equation, and y.Use the plot() method to plot the lines.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame([ ["y=x^3", 0, 0], ["y=x^3", 1, 1], ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To show multiple colorbars in matplotlib, we can take the following steps−Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Initialize a variable N for the number of sample data.Create random data1 using numpy.Display data as an image, i.e., on a 2D regular raster, with data1.Add a colorbar to a plot.Repeat steps 4, 5, and 6, with different datasets and axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1) N ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
6K+ Views
To show a plot in Flask, we can take the following steps−Make a small application.To run Flask application, go to the current directory.$ export FLASK_APP=file.py$ flask runOpen the browser, hit url:http://127.0.0.1:5000/print-plot/To plot the figure, we can create data points for x and y using random.Plot data points, x and y, on the created axis.Write a figure into png figure format.Retrieve the entire contents of the BytesIO object.Exampleimport io from flask import Response from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from flask import Flask import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True app = Flask(__name__) ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
496 Views
To write unit test cases against a code, we can consider a plot that takes an array as x points and plot it as y=x^2. While testing, we would extract y_data for x data points.−StepsCreate a method, i.e., plot_sqr_curve(x) to plot x and x^2 using plot() method and return the plot.To test, use unittest.TestCase.Write test_curve_sqr_plot() method that includes the following statements.Create data points for x to plot the curve.Using the above x data points, create y data points.Using x and y data points, plot the curve.Using pt (from step 5), extract x and y data.Check whether the given expression is ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To store mouse event coordinates with matplotlib, we can use "button_press_event" event.−StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a line in the range of 10Bind the function *onclick* to the event *button_press_event*.Print the x and y data of the event.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams['backend'] = 'TkAgg' plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Function to print mouse click event coordinates def onclick(event): print([event.xdata, event.ydata]) # Create a figure and a set of subplots fig, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
417 Views
To show mouse release event coordinates with matplotlib, we can take the following steps−Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a line in the range of 10.Bind the function *onclick* to the event *button_release_event*.Print event and its x and y data.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams['backend'] = 'TkAgg' plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def onclick(event): print(event.button, event.xdata, event.ydata) fig, ax = plt.subplots() ax.plot(range(10)) fig.canvas.mpl_connect('button_release_event', onclick) plt.show()OutputMouseButton.LEFT 4.961566107601828 1.6644009000562534 MouseButton.LEFT 6.782345894140708 3.7026907931745727 MouseButton.LEFT 2.98552602918754 7.177807987999249Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
428 Views
To change the axis tick font in matplotlib when rendering using LaTeX, we can take the following Steps −Create x and y data points using numpy.Using subplot() method, add a subplot to the current figure.Set x and y ticks with data points x and y using set_xticks and set_yticks methods, respectively.Plot x and y using plot() method with color=red.To set bold font weight, we can use LaTeX representation.To display the figure, use 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.array([1, 2, 3, 4]) y = np.exp(x) ax1 = ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To plot a bar graph from a Pandas series in matplotlib, we can take the following Steps −Make a dictionary of different keys, between the range 1 to 10.Make a dataframe using Pandas data frame.Create a bar plot using plot() method with kind="bar".To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True d = {'y=1/x': [1 / i for i in range(1, 10)], 'y=x': [i for i in range(1, 10)], 'y=x^2': [i * i for i in range(1, 10)], 'y=x^3': [i * i * ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To plot a circle with an edgecolor in matplotlib, we can take the following Steps −Create a new figure or activate an existing figure using figure() method.Add a subplot method to the current axis.Create a circle instance using Circle() class with an edgecolor and linewidth of the edge.Add a circle path on the plot.To place the text in the circle, we can use text() method.Scale the X and Y axes using xlim() and ylim() methods.To display the figure, use show() method.Exampleimport matplotlib from matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
16K+ Views
To rotate tick labels in a subplot, we can use set_xticklabels() or set_yticklabels() with rotation argument in the method.Create a list of numbers (x) that can be used to tick the axes.Get the axis using subplot() that helps to add a subplot to the current figure.Set ticks on the X and Y axes using set_xticks and set_yticks methods, respectively, and the list x (from step 1).Set tick labels with label lists (["one", "two", "three", "four"]) and rotation=45 using set_xticklabels() and set_yticklabels().To add space between axes and tick labels, we can use tick_params() method with pad argument that helps to add ... Read More