
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 10476 Articles for Python

949 Views
To get empty tick labels before showing a plot in matplotlib, we can take the following Steps −Create a list of data points.Add a subplot to the current figure using subplot() method.Set ticks and ticklabels using set_xticks() method and set_xticklabels() method.To get the empty tick labels, use get_xticklabels(which='minor').To display the method, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 2, 3, 4] ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_xticklabels(["one", "two", "three", "four"]) print("Empty tick labels: ", ax1.get_xticklabels(which='minor')) plt.show()OutputRead More

3K+ Views
Matplotlib does not support the functionality to plot implicit equations, however, you can try a code like the one we have shown here.StepsCreate xrange and yrange data points using numpy.Return coordinate matrices from coordinate vectors using meshgrid() method.Create an equation from x and y.Create a 3D contour using contour() method with x, y and the equation.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 delta = 0.025 xrange = np.arange(-5.0, 20.0, delta) yrange = np.arange(-5.0, 20.0, delta) x, y = np.meshgrid(xrange, yrange) equation = np.sin(x) - ... Read More

779 Views
Gaussian filtering an image with NaN values makes all the values of a matrix NaN, which produces an NaN valued matrix.StepsCreate a figure and a set of subplots.Create a matrix with NaN value in that matrix.Display the data as an image, i.e., on a 2D regular raster, data.Apply Gaussian filter on the data.Display the data as an image, i.e., on a 2D regular raster, gaussian_filter_data.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt from scipy.ndimage import gaussian_filter plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axes = plt.subplots(2) data = np.array([[1., 1.2, 0.89, ... Read More

3K+ Views
To set the aspect ratio of a 3D plot in matplotlib, we can take the following steps−Using figure() method, create a new figure or activate an existing figure.Get the current axes, creating one if necessary, with projection='3d'.Create data points, R, Y and z, using numpy.Create a surface plot using R, Y and z.Set the aspect ratio using set_aspect('auto').Save the figure using savefig() method.Examplefrom matplotlib import pyplot as plt from matplotlib import cm import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.gca(projection='3d') R, Y = np.meshgrid(np.arange(0, 100, 1), np.arange(0, 60, 1)) z = ... Read More

3K+ Views
To plot data into imshow() with custom colormap in matplotlib, we can take the following steps−Set the figure size and adjust the padding between and around the subplots.Create random data points using numpy.Generate a colormap object from a list of colors.Display the data as an image, i.e., on a 2D regular rasterTo display the figure, use show() method.Examplefrom matplotlib import pyplot as plt from matplotlib.colors import ListedColormap import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(5, 5) cmap = ListedColormap(['r', 'g', 'b']) plt.imshow(data, cmap=cmap) plt.show()OutputRead More

879 Views
To turn off error bars in a Seaborn bar plot, we can take the following steps−Load an example dataset from the online repository (requires Internet).Show the point estimates and confidence intervals with bars.To display the figure, use show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = sns.load_dataset('titanic') sns.barplot(x='class', y='age', hue='survived', data=df, ci=None) plt.show()Output

5K+ Views
To set the number of ticks in a colorbar, we can take the following steps−Create random data using numpyDisplay the data as an image, i.e., on a 2D regular raster.Make a colorbar using colorbar() method with an image scalar mappable object.Set the ticks and tick labels of the colorbar using set_ticks() and set_ticklabels() methods.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 data = np.random.rand(4, 4) im = plt.imshow(data, cmap="copper") cbar = plt.colorbar(im) cbar.set_ticks([0.2, 0.4, 0.6, 0.8]) cbar.set_ticklabels(["A", "B", "C", "D"]) plt.show()OutputRead More

2K+ Views
To modify the outline color of a node in networkx, we can use set_edgecolor() method.StepsCreate a Pandas dataframe with from and to keys.Return a graph from Pandas DataFrame containing an edge list.Get the position of the nodes.Draw the nodes of the graph using draw_networkx_nodes().Set the outline color of the nodes using set_edgecolor().To display the figure, use show() method.Examplefrom networkx import * import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'from': ['A', 'B', 'C', 'A'], 'to': ['D', 'A', 'E', 'C']}) G = nx.from_pandas_edgelist(df, 'from', 'to') pos = spring_layout(G) nodes = draw_networkx_nodes(G, pos) ... Read More

16K+ Views
To change the font size of ticks of a colorbar, we can take the following steps−Create a random data set of 5☓5 dimension.Display the data as an image, i.e., on a 2D regular raster.Create a colorbar with a scalar mappable object image.Initialize a variable for fontsize to change the tick size of the colorbar.Use axis tick_params() method to set the tick size of the colorbar.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 data = np.random.rand(5, 5) im = plt.imshow(data, interpolation="nearest", cmap="copper") cbar = plt.colorbar(im) tick_font_size ... Read More

2K+ Views
To set Step on X-axis in a figure in Matplotlib Python, we can take the following Steps −StepsCreate a list of data points, x.Add a subplot to the current figure using subplot() method.Set xticks and ticklabels with rotation=45.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 2, 3, 4] y = [1.2, 1.9, 3.1, 4.2] plt.plot(x,y) ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_xticklabels(["one", "two", "three", "four"], rotation=45) plt.show()Output