
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 26504 Articles for Server Side Programming

1K+ Views
To change the spacing of dashes in a dashed line in matplotlib, we can take the following steps −Create data points x and y using numpy.Initialize two variables space and dash_len with value 3.Plot x and y using plot() method, with line style '--', dashes tuple stores the property of dashed line.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 x = np.linspace(-1, 1, 100) y = np.sin(x) space = 3 dash_len = 3 plt.plot(x, y, c='red', linestyle='--', dashes=(dash_len, space), lw=5) plt.show()OutputRead More

5K+ Views
To set the ticks on a fixed position in matplotlib, we can take the following steps −Create a figure and add a set of subplots.To set the ticks on a fixed position, create two lists with some values.Use set_yticks and set_xticks methods to set the ticks on the axes.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 fig, ax = plt.subplots() xtick_loc = [0.20, 0.75, 0.30] ytick_loc = [0.12, 0.80, 0.76] ax.set_xticks(xtick_loc) ax.set_yticks(ytick_loc) plt.show()Output

1K+ Views
To plot a step function with matplotlib in Python, we can take the following steps −Create data points for x and y.Make a step plot using step() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([1, 3, 4, 5, 7]) y = np.array([1, 9, 16, 25, 49]) plt.step(x, y, 'r*') plt.show()Output

8K+ Views
To rotate xtick labels through 90 degrees, we can take the following steps −Make a list (x) of numbers.Add a subplot to the current figure.Set ticks on X-axis.Set xtick labels and use rotate=90 as the arguments in the method.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] ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_xticklabels(["one", "two", "three", "four"], rotation=90) plt.show()Output

277 Views
To make a simple 3D line with matplotlib, we can take the following steps −Create a new figure or activate an existing figure.Add axes to the figure as part of a subplot arrangement.Create data points for theta, z, r, x and y using numpy.Plot x, y and z using plot() method.Place a legend on the figure using legend() method.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 fig = plt.figure() ax = fig.add_subplot(projection='3d') theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) r ... Read More

4K+ Views
To plot multiple histograms on same plot with Seaborn, we can take the following steps −Create two lists (x and y).Create a figure and add a set of two subplots.Iterate a list consisting of x and y.Plot a histogram with histplot() method using the data in the list (step 3).Limit the X-axis range from 0 to 10.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 5, 1, 4, 2] y = [7, 5, 6, 4, 5] fig, ax = plt.subplots() for a in [x, y]: ... Read More

6K+ Views
To change the color of a plot frame, we can set axes ticklines and spine value into a specific color.StepsCreate a figure and add a set of subplots, using subplots method with value 4.Zip colors with axes and iterate them together.In the iteration, set the color for spines values and ticklines (x, y).Adjust the padding between and around the subplots.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 fig, (ax1, ax2, ax3, ax4) = plt.subplots(4) for ax, color in zip([ax1, ax2, ax3, ax4], ['green', 'red', 'yellow', 'blue']): plt.setp(ax.spines.values(), color=color) ax.plot([8, 3], ... Read More

1K+ Views
To annotate time series plot in matplotlib, we can take the following steps −Create lists for time and numbers.Using subplots() method, create a figure and a set of subplots.Using plot_date() method, plot the data that contains dates with linestyle "-.".Annotate a point in the plot using annotate() method.Date ticklabels often overlap, so it is useful to rotate them and right-align them.To display the figure, use show() method.Exampleimport datetime as dt from matplotlib import pyplot as plt, dates as mdates plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [dt.datetime(2021, 1, 1), dt.datetime(2021, 1, 2), dt.datetime(2021, 1, 3), dt.datetime(2021, 1, 4)] y = ... Read More

370 Views
To insert statistical annotation, we can take the following steps −Create lists (x and y) of numbers.Using subplots() method, create a figure and a set of subplots.Using plot() method, plot the data that contains dates with linestyle "-.".Annotate a point in the plot using annotate() method, mean of x and y.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 x = np.linspace(-1, 1, 5) y = np.linspace(-2, 2, 5) mean_x = np.mean(x) mean_y = np.mean(y) fig, ax = plt.subplots() ax.plot(x, y, linestyle='-.') ax.annotate('*', (mean_y, mean_y), xytext=(-.50, 1), arrowprops=dict(arrowstyle='-|>')) ... Read More

3K+ Views
To annotate data points while plotting from pandas data frame, we can take the following steps −Create df using DataFrame with x, y and index keys.Create a figure and a set of subplots using subplots() method.Plot a series of data frame using plot() method, kind='scatter', ax=ax, c='red' and marker='x'.To annotate the scatter point with the index value, iterate the data frame.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt import string plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'x': np.random.rand(10), 'y': np.random.rand(10)}, index=list(string.ascii_lowercase[:10])) fig, ax = plt.subplots() df.plot('x', ... Read More