Found 784 Articles for Data Visualization

Changing the color of a single X-axis tick label in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:59:29

3K+ Views

To change the color of a single X-axis tick label 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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Create x and y data points using numpy.Plot x and y data points using plot() method.To set the color of X-axis tick label in matplotlib, we can use tick_params() method with axis='x' and color='red'.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] ... Read More

How to appropriately plot the losses values acquired by (loss_curve_) from MLPClassifier? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:59:03

1K+ Views

To appropriately plot losses values acquired by (loss_curve_) from MLPCIassifier, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a params, a list of dictionaries.Make a list of labels and plot arguments.Create a figure and a set of subplots, with nrows=2 and ncols=Load and return the iris dataset (classification).Get x_digits and y_digits from the dataset.Get customized data_set, list of tuples.Iterate zipped, axes, data_sets and the list of name of titles.In the plot_on_dataset() method; set the title of the current axis.Get the Multi-layer Perceptron classifier instance.Get mlps, i.e a list of ... Read More

How to use Font Awesome symbol as marker in matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:41:02

211 Views

To use Font Awesome symbol as a marker, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of symbols; has to be plotted.Create x and y data points using numpy.Create a new figure or activate an existing figure using figure() method.Iterate the symbols and use it while plotting a line.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 symbols = [u'\u2B21', u'\u263A', u'\u29C6', u'\u2B14', u'\u2B1A', u'\u25A6', u'\u229E', u'\u22A0', u'\u22A1', u'\u20DF'] x = np.arange(10) ... Read More

How to save a Librosa spectrogram plot as a specific sized image?

Rishikesh Kumar Rishi
Updated on 15-Feb-2022 06:01:42

4K+ Views

Librosa is a Python package that helps to analyse audio and music files. This package also helps to create music retrieval information systems. In this article, we will see how to save a Librosa spectrogram plot as an image of specific size.StepsSet the figure size and adjust the padding between and around the subplots..Create a figure and a set of subplots.Initialize three different variables, hl, hi, wi, to store samples per time in the spectrogram, height and width of the images.Load a demo track.Create a window, i.e., a list for audio time series..Compute a mel-scaled spectrogram, using melspectrogram() with window ... Read More

How to plot an image with non-linear Y-axis with Matplotlib using imshow?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:35:11

713 Views

To plot an image with non-linear Y-axis with matplotlib using imshow() method, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Add a subplot to the current figure.Set nonlinear Y-axis ticks.Create random data points using numpy.Display data as an image, i.e., on a 2D regular raster, with data.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 ax = plt.subplot(111) ax.yaxis.set_ticks([0, 2, 4, 8]) data = np.random.randn(5, 5) plt.imshow(data, cmap='copper') plt.show()OutputRead More

How to create a matplotlib colormap that treats one value specially?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:33:09

497 Views

To create a matplotlib colormap that treats one value specially, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get a colormap instance, name is "rainbow".Set the color for low out-of-range values, using set_under('red') method.Create random data and eps using numpy.Create a figure and a set of subplots.Display data as an image, i.e., on a 2D regular raster, using imshow() method.Create a colorbar for a ScalarMappable instance, im.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 cmap ... Read More

How to show a figure that has been closed in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:31:25

723 Views

To show a figure that has been closed in Matplotlib, we can create a new Canvas Manager and store the previous figure into a new Canvas figure.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Create x and y data points using numpy.Plot x and y data points using plot() method.Close the current figure where the plot has been plotted.Now, store the previous figure in a new Canvas figure.Set the Canvas that contains the figure.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as ... Read More

How to set the Y-axis in radians in a Python plot?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:29:24

721 Views

To set the Y-axis in radians in a Python plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data point using numpy.Create a new figure or activate an existing figure using figure() method.Add an axes, ax, to the figure as part of a subplot arrangement.Get the list of Y-axis ticks and ticklabels.Set the ticks and ticklabels using set_yticks() and set_yticklabels() methods.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.arange(-10.0, ... Read More

How to plot histograms from dataframes in Pandas using Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:24:36

474 Views

To plot histograms against Pandas/Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a potentially hetrogeneous tabular data using Pandas dataframe.Use the dataframe to make a histogram.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'a': [1, 1, 1, 1, 3],    'b': [1, 1, 2, 1, 3],    'c': [2, 2, 2, 1, 3],    'd': [2, 1, 2, 1, 3], }) df.hist() plt.show()Output

How can box plot be overlaid on top of swarm plot in Seaborn?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:22:32

378 Views

To plot a Box plot overlaid on top of a Swarm plot in Seaborn, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe, i.e., two-dimensional, size-mutable, potentially heterogeneous tabular data.Initialize the plotter, swarmplot.To plot the box plot, use boxplot() method.To display the figure, use show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = pd.DataFrame({"Box1": np.arange(10), "Box2": np.arange(10)}) ax = sns.swarmplot(x="Box1", y="Box2", data=data, zorder=0) sns.boxplot(x="Box1", y="Box2", data=data, showcaps=False, ... Read More

Advertisements