
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 33676 Articles for Programming

1K+ Views
To remove the outline of a circle marker, we can reduce the value of marker edge width.Initialize list for x and y, with a single value.Limit x and y axis range for 0 to 5.Lay out a grid in current line style.Plot the given x and y using plot() method, with marker="o", markeredgecolor="red", markerfacecolor="green" and minimum markeredgewidth to remove the outline.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [4] y = [3] plt.xlim(0, 5) plt.ylim(0, 5) plt.grid() plt.plot(x, y, marker="o", markersize=20, markeredgecolor="black", markerfacecolor="green", markeredgewidth=.1) plt.show()OutputRead More

2K+ Views
To plot a Venn diagram, first install Venn diagram using command "pip install matplotlib-venn". Using venn3, plot a 3-set area-weighted Venn diagram.StepsCreate 3 sets.Using venn3, make a Venn diagram.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib_venn import venn3 plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True set1 = {'A', 'B', 'C'} set2 = {'A', 'B', 'D'} set3 = {'A', 'E', 'F'} venn3([set1, set2, set3], ('Group1', 'Group2', 'Group3')) plt.show()Output

1K+ Views
To imporove the label placement for matplotlib scatter chart, we can first plot the scatter points and annotate those points with labels.StepsCreate points for x and y using numpy.Create labels using xpoints.Use scatter() method to scatter points.Iterate the labels, xpoints and ypoints and annotate the plot with label, x and y with different properties.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 10, 10) ypoints = np.random.rand(10) labels = ["%.2f" % i for i in xpoints] plt.scatter(xpoints, ypoints, c=xpoints) for label, x, y in zip(labels, xpoints, ypoints): ... Read More

2K+ Views
To plot bar graphs with same X coordinates (G1, G2, G3, G4 and G5), side by side in matplotlib, we can take the following steps −Create the following lists – labels, men_means and women_means with different data elements.Return evenly spaced values within a given interval, using numpy.arrange() method.Set the width variable, i.e., width=0.35.Create fig and ax variables using subplots method, where default nrows and ncols are 1.The bars are positioned at *x* with the given *align*\ment. Their dimensions are given by *height* and *width*. The vertical baseline is *bottom* (default 0), so create rect1 and rect2 using plt.bar() method.Set the Y-axis label using plt.ylabel() ... Read More

603 Views
To plot scatter points using plot method in matplotlib, we can take the following steps−Create random data points (x1 and x2) using numpy.Plot x1 data points using plot() method with marker size 20 and green color.Plot x2 data points using plot() method with marker size 10 and red color.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x1 = np.random.randn(20) x2 = np.random.randn(20) plt.plot(x1, 'go', markersize=20) plt.plot(x2, 'ro', ms=10) plt.show()Output

438 Views
To create a standard colorbar for a series of plots, we can take the following steps −Create random data using numpy.Create a figure and a set of subplot using subplots() method, where nrows=1 and ncols=1.Display data as an image.Add an axes to the figure, for colorbar.Create a colorbar where mappable instance is image and cax where color will be drawn.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 data = np.random.rand(4, 4) fig, ax = plt.subplots(nrows=1, ncols=1) im = ax.imshow(data) cax = fig.add_axes([0.9, 0.1, 0.03, 0.8]) fig.colorbar(im, cax=cax) ... Read More

7K+ Views
To change the formatting of a datetime axis in matplotlib, we can take the following steps−Create a dataframe df using pandas DataFrame with time and speed as keysCreate a figure and a set of subplots using subplots() method.Plot the dataframe using plot method, with df's (Step 1) time and speed.To adjust the tick labels, we can rotate tick_params by 45 degreesTo edit the date formatting from %d-%m-%d to %d:%m%d, we can use set_major_formatter() method. Set the formatter of the major ticker.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt, ... Read More

5K+ Views
To save a figure as a file from iPython, we can take the following steps−Create a new figure or activate an existing figure.Add an axes to the figure using add_axes() method.Plot the given list.Save the plot using savefig() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_axes([1, 1, 1, 1]) plt.plot([1, 2]) plt.savefig('test.png', bbox_inches='tight')OutputWhen we execute the code, it will save the following plot as "test.png".

3K+ Views
To plot 2D math vectors with matplotlib, we can take the following steps−Create vector cordinates using numpy array.Get x, y, u and v data points.Create a new figure or activate an existing figure using figure method.Get the current axis using gca() method.Set x an y limits of the axes.To redraw the current figure, use draw() method.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 soa = np.array([[0, 0, 3, 2], [0, 0, 4, 5], [0, 0, 9, 9]]) X, Y, U, V = zip(*soa) plt.figure() ax = plt.gca() ... Read More

1K+ Views
To wrap long Y label in matplotlib tight layput using setp, we can take the following steps−Create a list of a long strings.Create a tuple of 3 values.Create a figure and add a set of subplots.Limit the Y-axis ticks using ylim() method.Make a horizontal bar plot, using barh() method.Use yticks() method to ticks the yticks.Use setp() method to set a property on an artist object.Use tight_layout() method to adjust the padding between and around subplots.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 labels = ( ... Read More