Found 784 Articles for Data Visualization

How to plot masked and NaN values in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:15:39

3K+ Views

To plot masked and NaN values 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.Get x2 and y2 data points such that y > 0.7.Get masked y3 data points such that y > 0.7.Mask y3 with NaN values.Plot x, y, y2, y3 and y4 using plot() method.Place a legend to the plot.Set the title of the plot.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 x = ... Read More

How to Zoom with Axes3D in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:14:51

1K+ Views

To zoom with Axes3D, 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.Get 3D axes object using Axes3D(fig) method.Plot x, y and z data points using scatter() method.To display the figure, use show() method.Examplefrom mpl_toolkits.mplot3d import Axes3D from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = Axes3D(fig) x = [2, 4, 6, 3, 1] y = [1, 6, 8, 1, 3] z = [3, 4, 10, 3, 1] ... Read More

How to move labels from bottom to top without adding "ticks" in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:16:03

701 Views

To move labels from bottom to top without adding ticks, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data of 5☓5 dimension matrix.Display the data as an image, i.e., on a 2D regular raster using imshow() method.Use tick_params() method to move labels from bottom to top.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 data = np.random.rand(5, 5) plt.imshow(data, cmap="copper") plt.tick_params(axis='both', which='major',                labelsize=10, labelbottom=False, ... Read More

How to plot scatter masked points and add a line demarking masked regions in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:16:29

303 Views

To plot scattered masked points and add a line to demark the masked regions, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Create N, r0, x, y, area, c, r, area1and area2 data points using numpy.Plot x and y data points using scatter() method.To demark the maked regions, plot the curve using plot() 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 N = 100 r0 = 0.6 x = 0.9 * np.random.rand(N) y = 0.9 * ... Read More

How to a plot stem plot in Matplotlib Python?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:56:19

3K+ Views

To plot a stem plot in Matplotlib, we can use stem() method. It creates vertical lines from a baseline to the Y-coordinate and places a marker at the tip.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a stem plot using stem() method.Set the marker face color with red color.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 x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) markerline, stemlines, baseline = plt.stem(x, y, ... Read More

How to refresh text in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:49:05

1K+ Views

To refresh text in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Add text to the axes.Write customized method to update text based on the keys "z" and "c".Bind the function action with key_press_event.Draw the canvas that contains the figure.Animate the figure with texts.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() text = ax.text(.5, .5, 'First Text') def action(event):    if event.key == "z":   ... Read More

How to make xticks evenly spaced despite their values? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:48:42

3K+ Views

To make xticks evenly spaced despite their values, we can use set_ticks() and set_ticklabels() methods.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.Plot x and y data points on axis 1.Set xticks using xaxis.set_ticks() method.Plot x and y data points on axis 2.Set xticks and ticklabels using xaxis.set_ticks() and xaxis.set_ticklabels() 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.array([1, 1.5, ... Read More

Stuffing a Pandas DataFrame.plot into a Matplotlib subplot

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:47:56

2K+ Views

To stuff a Pandas dataframe plot into a Matplotlib subplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots, two axes.Create a Pandas dataframe using DataFrame.Use DataFrame.plot() method to plot.To display the figure, use show() method.Exampleimport pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2) = plt.subplots(2) df = pd.DataFrame(dict(name=["Joe", "James", "Jack"], age=[23, 34, 26])) df.set_index("name").plot(ax=ax1) df.set_index("name").plot(ax=ax2) plt.show()OutputRead More

How to get boxplot data for Matplotlib boxplots?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:42:51

3K+ Views

To get boxplot data for Matplotlib boxplot we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make data frame using pandas.Make a box plot from DataFrame columns.Get boxplot's outliers, boxes, medians and whiskers data.Prit all the above information.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(age=[23, 45, 21, 15, 12])) _, bp = pd.DataFrame.boxplot(df, return_type='both') outliers = [flier.get_ydata() for flier in bp["fliers"]] boxes = [box.get_ydata() for box in ... Read More

Draw a parametrized curve using pyplot.plot() in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:25:18

3K+ Views

To draw a parametrized curve using pyplot.plot(), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of samples.Create t, r, x and y data points using numpy.Create a figure and a set of subplots.Use plot() method to plot x and y data points.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 N = 400 t = np.linspace(0, 2 * np.pi, N) r = 0.5 + np.cos(t) x, y = r * ... Read More

Advertisements