Turn Off Left and Bottom Axis Tick Marks in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:03:11

556 Views

To turn off the left or bottom axis tick marks in matplotlib, we can use length=0 for the axes.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Use tick_params() method with length=0.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 x = np.linspace(-2, 2, 10) y = np.sin(x) plt.plot(x, y) plt.tick_params(axis='both', which='both', length=0) plt.show()OutputRead More

Setting Spacing Between Grouped Bar Plots in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:02:08

3K+ Views

To set the spacing between grouped bar plots in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dictionary for bar details to be plotted.Make a Pandas dataframe using dictionary, d.Plot the bar using dictionary, d, with align="center".To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True d = {"Name": ["John", "Jacks", "James", "Joe"], "Age": [23, 12, 30, 26], "Marks": [98, 85, 70, 77]} df = pd.DataFrame(d) df.set_index('Name').plot(kind="bar", align='center', width=0.1) plt.tick_params(rotation=45) plt.show()OutputRead More

Show Two Different Colored Colormaps in imshow Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 13:00:42

2K+ Views

To show two different colored colormaps in the same imshow matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a 2D matrix of 5×5 dimension.Get masked matrix, data1 and data2, with positive and negative values.Create a figure and a set of subplots.Display the data as an image, i.e., on a 2D regular raster, with data1 and data2.To make two different colorbars, use colorbar method.Set the colorbar for both the images.Set the label of the colorbars.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np ... Read More

Make Custom Grid Lines in Seaborn Heatmap

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:57:23

5K+ Views

To make custom grid lines in Seaborn heatmap, we can use linewidths and linecolor values in the heatmap() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe with 5 columns.Use heatmap() method to plot the rectangular data as a color-encoded matrix.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["col1", "col2", "col3", "col4", "col5"]) sns.heatmap(df, linewidths=4, linecolor='green') plt.show()OutputRead More

Plot Scatter Points in a 3D Figure with Colorbar in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:55:07

3K+ Views

To plot scatter points in a 3D figure with a colorbar in matplotlib, we can use the scatter() and colorbar() methods.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an axis as a subplot arrangement.Create xs, ys and zs data points using numpy.Use scatter() method to create a scatter plot.Use colorbar() method with scatter scalar mappable instance for colorbar.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 fig = plt.figure() ax ... Read More

Line Colour of a 3D Parametric Curve in Python's Matplotlib Pyplot

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:51:08

429 Views

To plot the line color of a 3D parametric curve in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an axis as a subplot arrangement.To make a parametric curve, initialize theta, z, r, x  and y variables.Plot x, y and z data points using scatter() method.Set the title of the plot.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 fig = plt.figure() ax = fig.add_subplot(projection='3d') ... Read More

Show Mean in a Box Plot Using Matplotlib in Python

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:48:06

3K+ Views

To show mean in a box plot, we can use showmeans=True in the argument of boxplot() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a random dataset.Create a new figure or activate an existing figure using figure() method.Add an axes to the current figure as a subplot arrangement.Make a box and whisker plot using boxplot() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(100, 5) fig = plt.figure() ax = fig.add_subplot(111) bp = ax.boxplot(data, 'd', showmeans=True) plt.show()OutputRead More

Shade Points in Scatter Based on Colormap in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:45:27

620 Views

To shade points in a scatter based on colormap, we can use copper colormap in scatter() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y random 100 data points using numpy.Plot scatter points x and y with color=x and colormap=copper.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(100) y = np.random.rand(100) plt.scatter(x, y, c=x, cmap='copper') plt.show()Output

Use Custom PNG Image Marker in a Plot with Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:43:25

5K+ Views

To use custome png or jpg i.e an image as a marker in a plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a paths list to store the directories of images.Make a list (x and y) of points.Using subplots() method, create a figure and a set of subplots.To plot images instead of points, iterate zipped x, y and paths.Instantiate AnnotationBbox() with image and (x, y) points.Put xticks and yticks on both the axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.offsetbox import OffsetImage, AnnotationBbox ... Read More

Plot 3D Continuous Line in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:41:28

6K+ Views

To plot a 3D continuous line in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create z data points using x and y data points.Create a new figure or activate an existing figure using figure() method.Add an axes as a subplot arrangement with 3D projection.Plot x, y and z data points using plot() method.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(-4 * np.pi, 4 ... Read More

Advertisements