
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

2K+ Views
To logscale plots with zero values in matplotlib, we can use xscale() and yscale() methods with "symlog" class by name.StepsSet the figure size and adjust the padding between and around the subplots.Plot two lists containing zero values using plot() method.Use yscale() method with "symlog" class by name.Use xscale() method with "symlog" class by name.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([0, 1, 2, 0, 3], [1, 0, 2, 3, 5], marker='o', linestyle='-') plt.yscale('symlog') plt.xscale('symlog') plt.show()Output

4K+ Views
The matplotlib is a library in Python that allows us to create graphs and plots for data visualization. This library have several built-in functions to style the plots, such as changing colors, adding titles, setting backgrounds, labels, and adjusting the layout of subplots. In this article, we will learn how to adjust the transparency of text backgrounds in matplotlib plots. Text Backgrounds in Matplotlib Adjusting Background Transparency of Title Text Adjusting Background Transparency of Labels Conclusion Text Backgrounds in Matplotlib ... Read More

5K+ Views
To plot a dashed line on a Seaborn lineplot, we can use linestyle="dashed" in the argument of lineplot().StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use lineplot() method with x and y data points in the argument and linestyle="dashed".To display the figure, use show() method.Exampleimport seaborn as sns import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(10) y = np.random.rand(10) ax = sns.lineplot(x=x, y=y, linestyle="dashed") plt.show()OutputRead More

1K+ Views
To skip weekends in a financial graph in matplotlib, we can iterate the time in dataframe and skip the plot if weekday is 5 or 6.StepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe with keys time.Iterate zipped index and time of a date frame.If iterated timestamp is having weekday 5 or 6, don't plot them.Other than 5 or 6 weekday, plot the points.Set the current tick locations of Y-axis.Lay out a plot with grid lines.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, ... Read More

1K+ Views
We can use annotate() method to place annotation outside the drawing.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots using subplots() method.Use scatter() method to plot x and y data points using star marker and copper color map.To place annotation outside the drawing, use xy coordinates tuple accordingly.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(100) y = np.random.rand(100) fig, ax = plt.subplots() ax.scatter(x, y, ... Read More

3K+ Views
To plot a histogram for discrete values with matplotlib, we can use hist() method.StepsSet the figure size and adjust the padding between and around the subplots.Make a list of discrete values.Use hist() method to plot data with bins=length of data and edgecolor=black.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [1, 4, 2, 3, 5, 9, 6, 7] plt.hist(data, bins=len(data), edgecolor='black') plt.show()Output

1K+ Views
To plot only the upper/lower triangle of a heatmap in matplotlib, we can use numpy to get the masked 2D array and convert them into an image to produce a heatmap.StepsSet the figure size and adjust the padding between and around the subplots.Create a random data of 5×5 dimension.Use numpy.tri() method to create an array with 1's at and below the given diagonal and 0's elsewhere.Get the masked 2D array data with masked array (Using step 3).Use imshow() method to display the data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Exampleimport numpy as ... Read More

593 Views
To control matplotlib marker orientation, we can use marker tuple that contains a number of sides, style and rotation or orientation of the marker.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Make an array of 10 different rotations.Zip x, y and i. Iterate them and plot the points using plot() method with marker tuple.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(10) y = np.random.rand(10) i = np.linspace(0, 10, 10) for x, ... Read More

3K+ Views
To change the linewidth of a hatch in matplotlib, we can set the linewidth of the hatch in the params.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y=sin(x) data points using numpy.Set the linewidth of the hatch in the plot.Plot x and y data points using scatter() method with a square marker having "/" hatches with set linewidth.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 25) y = np.sin(x) plt.rcParams['hatch.linewidth'] = 1 plt.scatter(x, y, ... Read More

983 Views
To add a custom border to certain cells in a Matplotlib/Seaborn plot.StepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe with some columns.Plot a matrix dataset as a hierarchically-clustered heatmap.Get heatmap axis as a subplot arrangement.To add a custom border to certain cells in Matplotlib, we can intialize a variable, border_color.Using custom bordder color, add a rectangle patch on the heatmap axes.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({"col1": [1, 4, 2, ... Read More