Found 784 Articles for Data Visualization

How to control the border of a bar patch in matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:35:09

5K+ Views

To control the border of a bar patch in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a list of heights and a tuple for labels.Use the bar() method with edgecolor in the argument to control the color of the bar patch. Here we have used edgecolor='green'.Set the ticks and labels of the X-axis.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True height = [3, 12, 5, 18, 45] labels = ('P1', 'P2', 'P3', 'P4', ... Read More

How to increase the line thickness of a Seaborn Line?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:21:02

3K+ Views

To increase the line thickness of a Seaborn line, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a Seaborn line plot with linewidth value in the argument. Here we have set linewidth=7.Rotate the tick params, i.e., labels by 45 degrees.To display the figure, use Show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt import pandas as pd import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(     dict(     ... Read More

How can I plot two different spaced time series on one same plot in Python Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:31:18

3K+ Views

To plot two different spaced time series on one same plot using Matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create x1, y1 and x2 and y2 data points.Create a figure and a set of subplots.Plot the data that contains dates, with (x1, y1) and (x2, y2) data points.Set the major formatter of the X-axis ticklabels.Rotate xtick label by 45 degrees using tick_params() method.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.dates import date2num, DateFormatter import datetime as dt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

How to change Bar Chart values to percentages in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:29:06

9K+ Views

To change bar chart values to percentage in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Make a list of frequencies.Create a new figure or activate an existing figure.Make a bar plot using bar() method.Iterate the bar plot and find the height of each patch and use annotate() method to put values in percentages.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 frequencies = [7, 8, 5, 3, 6] plt.figure() p1 = ... Read More

How to increase colormap/linewidth quality in streamplot Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:27:08

189 Views

To increase colormap/linewidth quality in streamplot matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Create x and y data points and then use np.meshgrid() to return the coordinate matrices from the coordinate vectors.Find X and Y using x and y data points.Create a streamplot with x, y, X and Y data points. You can increase the linewidth using the linewidth parameter in the method. Here we have used linewidth=5.Create a colorbar for a ScalarMappable instance, *stream.lines*.To display the figure, use Show() method.Exampleimport numpy ... Read More

How to adjust the space between Matplotlib/Seaborn subplots for multi-plot layouts?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:18:59

5K+ Views

To adjust the space between matplotlib/seaborn subplots for multi-plot layouts, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Adjust the subplot layout parameters.Create Seaborn's box plot for all the subplots.To display the figure, use Show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axes = plt.subplots(2, 2) # Adjust the subplot layout parameters fig.subplots_adjust(hspace=0.125, wspace=0.125) # Create Seaborn boxplot for all the subplots sns.boxplot(ax=axes[0, 0]) sns.boxplot(ax=axes[0, 1]) sns.boxplot(ax=axes[1, 0]) sns.boxplot(ax=axes[1, ... Read More

How to change the transparency/opaqueness of a Matplotlib Table?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:23:22

500 Views

To change the transparency/opaqueness of a matplotlib table, we can atke following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Create a random dataset with 10×3 dimension.Create a tuple of columns.Get rid of the axis markers using axis('off').Create a table with data and columns.Iterate each cell of the table and change its transparency/opaqueness using set_alpha() method.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 fig, axs = plt.subplots(1, 1) data = np.random.random((10, 3)) ... Read More

How to sort a boxplot by the median values in Pandas?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:17:33

1K+ Views

To sort a boxplot by the median values in Pandas, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe of two-dimensional, size-mutable, potentially heterogeneous tabular data, with three columns.Group the dataframe elements by marks and dob.Find the median of the dataframe.Get the sorted values of the median.Create a box plot from the DataFrame columns.To display the figure, use Show() method.Exampleimport pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame([     [23, 'James', 12],     [39, 'Jimmy', ... Read More

Embedding a matplotlib animation into a tkinter frame

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:15:07

4K+ Views

To embed a matplotlib animation into a tkinter frame, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a Toplevel widget of Tk which represents mostly the main window of an applicationSet the title of this widget.Add an axes to the current figure and make it the current axes.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Make a dummy line plot with linewidth=2.Create the canvas the figure renders into.Create the figure canvas on which to operate.Create a keypress event to ... Read More

Saving multiple figures to one PDF file in matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 09:06:44

4K+ Views

To save multiple figures in one PDF file at once, we can take follwong stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure (fig1) or activate and existing figure using figure() method.Plot the first line using plot() method.Create another figure (fig2) or activate and existing figure using figure() method.Plot the second line using plot() method.Initialize a variable, filename, to make a pdf file.Create a user-defined function save_multi_image() to save multiple images in a PDF file.Call the save_multi_image() function with filename.Create a new PdfPages object.Get the number of open figures.Iterate the opened figures and ... Read More

Advertisements