- 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
414 Views
In this program, we will plot a bar graph using the matplotlib library. The most important Step in solving matplotlib related problems using the matplotlib library is importing the matplotlib library. The syntax is:import matplotlib.pyplot as pltPyplot is a collection of command style functions that make Matplotlib work like MATLAB. In addition to plotting the bar graphs, we will also add some textures to the graphs. The 'hatch' parameter in the bar() function is used to define the texture of the barAlgorithmStep 1: Define a list of values. Step 2: Use the bar() function and define parameters like xaxis, yaxis, ... Read More
721 Views
In this program, we will plot a bar graph using the matplotlib library. The most important Step in solving matplotlib related problems using the matplotlib library is importing the matplotlib library. The syntax is:import matplotlib.pyplot as pltPyplot is a collection of command style functions that make Matplotlib work like MATLAB. We will use the function barh() for plotting the horizontal bar chartsAlgorithmStep 1: Define a list of values. Step 2: Use the barh() function in the matplotlib.pyplot library and define different parameters like height width, etc. Step 3: Label the axes using xlabel() and ylabel(). Step 3: Plot the graph ... Read More
8K+ Views
We can use the method, plt.figure(), to create the figures, and then, set their titles by passing strings as arguments.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Draw a line using plot() method, over the current figure.Create a new figure, or activate an existing figure, with the window title “Welcome to figure 2”.Draw a line using plot() method, over the current figure.Using plt.show(), show the figures.Examplefrom matplotlib import pyplot as plt plt.figure("Welcome to figure 1") plt.plot([1, 3, 4]) plt.figure("Welcome to figure 2") plt.plot([11, 13, 41]) plt.show()OutputRead More
4K+ Views
Get fig from plt.figure() and create three different axes using add_subplot, where projection=3d.Set up the figure title using ax.set_title("name of the figure"). Use the method ax.quiver to plot vector projection, plot3D for cube, and plot_wireframe for sphere after using sin and cos.StepsCreate a new figure, or activate an existing figure.To draw vectors, get a 2D array.Get a zipped object.Add an ~.axes.Axes to the figure as part of a subplot arrangement, with 3d projection, where nrows = 1, ncols = 3 and index = 1.Plot a 3D field of arrows.Set xlim, ylim and zlim.Set the title of the axis (at index ... Read More
190 Views
In this program, we will plot a bar graph using the matplotlib library. The most important Step in solving matplotlib related problems using the matplotlib library is importing the matplotlib library. The syntax is −import matplotlib.pyplot as pltPyplot is a collection of command style functions that make Matplotlib work like MATLABAlgorithmStep 1: Define a list of values. Step 2: Use the bar() function in the matplotlib.pyplot library and define different parameters like height, width, etc. Step 3: Label the axes using xlabel() and ylabel(). Step 3: Plot the graph using show().Example Codeimport matplotlib.pyplot as plt data_x = ['Mumbai', 'Delhi', ... Read More
515 Views
Using plt.rcParams["figure.figsize"], we can get the width setting.StepsTo get the plot width setting, use plt.rcParams["figure.figsize"] statement.Override the plt.rcParams["figure.figsize"] with a tuple (12, 9).After updating the width, get the updated width using plt.rcParams["figure.figsize"].ExamplesIn IDEExampleimport matplotlib.pyplot as plt print("Before, plot width setting:", plt.rcParams["figure.figsize"]) plt.rcParams["figure.figsize"] = (12, 9) print("Before, plot width setting:", plt.rcParams["figure.figsize"])OutputBefore, plot width setting: [6.4, 4.8] Before, plot width setting: [12.0, 9.0]In IPythonExampleIn [1]: from matplotlib import pyplot as plt In [2]: plt.rcParams["figure.figsize"]OutputOut[2]: [6.4, 4.8]
4K+ Views
We can set the logarithmic bins while plotting histogram using plt.hist(bin="").StepsCreate an array x, where range is 100.Plot a histogram using plt.hist() method. We can pass logarithmic bins using logarithmic bins that returns numbers spaced evenly on a log scale.Get the current axes, creating one if necessary and set the X-axis scale.To show the figure, use plt.show() method.Examplefrom matplotlib import pyplot as plt import numpy as np x = np.array(range(100)) plt.hist(x, bins=np.logspace(start=np.log10(10), stop=np.log10(15), num=10)) plt.gca().set_xscale("log") plt.show()OutputRead More
6K+ Views
First, we can get the axes. Then, ax.spines could help to set the color by specifying the name of the axes, i.e., top, bottom, right and left.StepsAdd an axes to the current figure and make it the current axes.Using step 1 axes, we can set the color of all the axes.Using ax.spines[axes].set_color(‘color’), set the color of the axes. Axes could be bottom, top, right, and left. Color could be yellow, red, black, and blue.To show the figure, use the plt.show() method.Examplefrom matplotlib import pyplot as plt ax = plt.axes() ax.spines['bottom'].set_color('yellow') ax.spines['top'].set_color('red') ax.spines['right'].set_color('black') ax.spines['left'].set_color('blue') plt.show()OutputRead More
12K+ Views
We can first create bars and then, by using set_color, we can set the color of the bars.StepsPass two lists consisting of four elements, into the bars method argument.Step 1 returns bars.Return values (0, 1, 2, 3) can be set with different colors, using set_color() method. Green, Black, Red color will be set and one bar will have the default color.To show the figure, use plt.show() method.Examplefrom matplotlib import pyplot as plt bars = plt.bar([1, 2, 3, 4], [1, 2, 3, 4]) bars[0].set_color('green') bars[1].set_color('black') bars[2].set_color('red') plt.show()Output
618 Views
Using the figure() method, we can set the current figure.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Create a new figure, or activate an existing figure, with the window title “Welcome to figure 2”.Using plt.show(), show the figures.Examplefrom matplotlib import pyplot as plt plt.figure("Welcome to figure 1") plt.figure("Welcome to figure 2") # Active Figure plt.show()Output
To Continue Learning Please Login
Login with Google