
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

2K+ Views
To let my matplotlib plot go beyond the axes, we can turn off the flag clip_on in the argument of plot() method.StepsCreate xs and ys data points using numpy.Limit the X and Y axis range in the plot to let the line go beyond this limit, using xlim() and ylim() method.Plot the xs and ys data points using plot() method, where marker is a diamond shape, color is orange and clip_on=False (to go beyond the plot).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 xs = np.arange(10) ys ... Read More

9K+ Views
To avoid overlapping of labels and autopct in a matplotlib pie chart, we can follow label as a legend, using legend() method.StepsInitialize a variable n=20 to get a number of sections in a pie chart.Create slices and activities using numpy.Create random colors using hexadecimal alphabets, in the range of 20.Use pie() method to plot a pie chart with slices, colors, and slices data points as a label.Make a list of labels (those are overlapped using autopct).Use legend() method to avoid overlapping of labels and autopct.To display the figure, use show() method.Exampleimport random import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = ... Read More

902 Views
To fix colors in scatter plots in matplotlib, we can take the following steps −Create xs and ys random data points using numpy.Create a set of colors using hexadecimal alpabets, equal to the length of ys.Plot the lists, xs and ys, using scatter() method, with the list of colors.To display the figure, use show() method.Exampleimport random import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True xs = np.random.rand(100) ys = np.random.rand(100) colors = ["#" + ''.join([random.choice('0123456789ABCDEF') for j in range(6)]) for i in range(len(xs))] plt.scatter(xs, ys, c=colors) plt.show()OutputRead More

3K+ Views
To plot two countplot graphs side by side in Seaborn, we can take the following steps −To create two graphs, we can use nrows=1, ncols=2 with figure size (7, 7).Create a dataframe with keys, col1 and col2, using Pandas.Use countplot() to show the counts of observations in each categorical bin using bars.Adjust the padding between and around the subplots.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True f, axes = plt.subplots(1, 2) df = pd.DataFrame(dict(col1=np.linspace(1, 10, 5), col2=np.linspace(1, ... Read More

1K+ Views
To set transparency based on pixel values in matplotlib, get masked data wherever data is less than certain values. Lesser value will result in full overlapping between two images.StepsCreate data1 and data2 using numpy.Get the masked data using numpy's masked_where() method.Using subplots() method, create a figure and a set of subplots (fig and ax).Display the data (data1 and masked data) as an image, i.e., on a 2D regular raster, using imshow() method, with different colormaps, jet and gray.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data1 = np.random.rand(50, 50) data2 = ... Read More

579 Views
To change the font size of ticks of axes object in matplotlib, we can take the following steps −Create x and y data points using numpy.Using subplots() method, create a figure and a set of subplots (fig and ax).Plot x and y data points using plot() method, with color=red and linewidth=5.Set xticks with x data points.Get the list of major ticks using get_major_ticks() method.Iterate the major ticks (from step 5), and set the font size and rotate them by 45 degrees.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 ... Read More

7K+ Views
To show decimal places and scientific notation on the axis of a matplotlib, we can use scalar formatter by overriding _set_format() method.StepsCreate x and y data points using numpy.Plot x and y using plot() method.Using gca() method, get the current axis.Instantiate the format tick values as a number class, i.e., ScalarFormatter.Set size thresholds for scientific notation, using set_powerlimits((0, 0)) method.Using set_major_formatter() method, set the formatter of the major ticker.To display the figure, use show() method.Exampleimport numpy as np from matplotlib.ticker import ScalarFormatter from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True class ScalarFormatterClass(ScalarFormatter): def _set_format(self): ... Read More

8K+ Views
To plot vectors in Python using matplotlib, we can take the following steps −Create a matrix of 2×3 dimension.Create an origin point, from where vecors could be originated.Plot a 3D fields of arrows using quiver() method with origin, data, colors and scale=15.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.array([[2, 1], [-1, 2], [4, -1]]) origin = np.array([[0, 0, 0], [0, 0, 0]]) plt.quiver(*origin, data[:, 0], data[:, 1], color=['black', 'red', 'green'], scale=15) plt.show()Output

2K+ Views
To rotate the rectangle patch in a plot, we can use angle in the Rectangle() class to rotate it.StepsCreate a figure and a set of subplots using subplots() method.Add a rectangle on the patch, angle=45°.Add a patch on the axis.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True figure, ax = plt.subplots(1) rectangle = patches.Rectangle((0.4, 0.25), 0.5, 0.5, edgecolor='orange', facecolor="green", linewidth=2, angle=45) ax.add_patch(rectangle) plt.show()Output

8K+ Views
To set ticks on a fixed position or change the spacing between ticks 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()OutputRead More