Found 784 Articles for Data Visualization

How is the Pyplot histogram bins interpreted? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:47:47

205 Views

To plot histogram bins interpreted with different bins, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of data to plot in histogram.Add a subplot to the current figure, nrows=1, ncols=3 and index=1.Plot a histogram with data; bins is a number.Add a subplot to the current figure, nrows=1, ncols=3 and index=2.Plot a histogram with data; bins is an array.Add a subplot to the current figure, nrows=1, ncols=3 and index=3.Plot a histogram with data, bins is a string.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

Annotating points from a Pandas Dataframe in Matplotlib plot

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:44:18

1K+ Views

To annotate points from a Pandas dataframe in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data, with x, y and textc columns.Plot the columns x and y data points, using plot() method.Concatenate Pandas objects along a particular axis with optional set logic along the other axes.Iterate the Pandas object.Place text for each plotted points using text() method.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 df = ... Read More

How to show a bar and line graph on the same plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:40:59

18K+ Views

To show a bar and line graph on the same plot in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a figure and a set of subplots.Plot the bar and line with the dataframe obtained from Step 2.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 df = pd.DataFrame(dict(data=[2, 4, 1, 5, 9, 6, 0, 7])) fig, ax = plt.subplots() df['data'].plot(kind='bar', color='red') df['data'].plot(kind='line', marker='*', color='black', ms=10) ... Read More

How to plot blurred points in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Aug-2021 06:33:56

691 Views

To plot blurred points 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 new figure.Add an ax1 to the figure as part of a subplot arrangement.First, we can make a marker, i.e., to be blurred.Set the X and Y axes scale, turn off the axes.Save the marker in a file, and load that image to be plotted after blurred.Close the previous figure, fig1.Create a new figure or activate an existing figure, fig2.Create random data points, x and y.Apply Gaussian filter, to ... Read More

How to create a Swarm Plot with Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Aug-2021 12:55:54

886 Views

To create a Swarm Plot with Matplotlib, 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., a two-dimensional, size-mutable, potentially heterogeneous tabular data.Initialize the plotter, swarmplot.To plot the boxplot, 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) ... Read More

How to display the matrix value and colormap in Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Aug-2021 12:55:08

4K+ Views

To display the matrix value and colormap 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.Initialize max and min values for matrix.Plot the values of a 2D matrix or array as color-coded image.Iterate each cell of the color-code image and place value at the center.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, ax = plt.subplots() min_val, max_val = 0, 5 matrix = np.random.randint(0, 5, size=(max_val, ... Read More

How to annotate a range of the X-axis in Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Aug-2021 12:54:32

1K+ Views

To annotate a range of the X-axis in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create xx and yy data points using numpy.Create a figure and a set of subplots.Plot xx and yy data points using plot() method.Set ylim of the axis.Use annotate method to place arrow heads and range tag name.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 xx = np.linspace(0, 10) yy = np.sin(xx) fig, ax = plt.subplots(1, 1) ... Read More

How to annotate several points with one text in Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Aug-2021 12:48:54

1K+ Views

To add annotated text in Matplotlib for several points, 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.To set the label for each scattered point, make a list of labels.Plot xpoints, ypoints using scatter() method. For color, use xpoints.Iterate zipped labels, xpoints and ypoints.Use annotate() method with bold LaTeX representation in a for loop.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 xpoints = np.linspace(1, 10, 10) ... Read More

How to plot a line in Matplotlib with an interval at each data point?

Rishikesh Kumar Rishi
Updated on 04-Aug-2021 12:47:05

2K+ Views

To plot a line in Matplotlib with an interval at each data point, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make an array of means and standard deviations.Plot means using plot() method.Fill the area between means+stds and means-stds, alpha=0.7 and color='yellow'.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 means = np.array([3, 5, 1, 8, 4, 6]) stds = np.array([1.3, 2.6, 0.78, 3.01, 2.32, 2.9]) plt.plot(means, color='red', lw=7) plt.fill_between(range(6), means - stds, means ... Read More

How to plot CSV data using Matplotlib and Pandas in Python?

Rishikesh Kumar Rishi
Updated on 26-Aug-2023 03:10:30

39K+ Views

To plot CSV data using Matplotlib and Pandas in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of headers of the .CSV file.Read the CSV file with headers.Set the index and plot the dataframe.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 headers = ['Name', 'Age', 'Marks'] df = pd.read_csv('student.csv', names=headers) df.set_index('Name').plot() plt.show()Output

Advertisements