Increase Thickness of Error Line in Matplotlib Bar Chart

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 12:00:56

1K+ Views

To increase the thickness of error line in a Matplotlib bar chart, we can use err_kw=dict() with their properties.StepsSet the figure size and adjust the padding between and around the subplots.Make a dictionary of bar details.Create a figure and a set of subplots.Use bar() method to make a bar plot with yerr and err_kwTo display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True bar_details = {    "labels": ['G1', 'G2', 'G3', 'G4', 'G5'],    "men_means": [20, 35, 30, 35, 27],    "men_std": [2, 3, 4, 1, 2],    "width": 0.35 } ... Read More

Plot Time Series Array with Confidence Intervals in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 12:00:25

3K+ Views

To plot a time series array, with confidence intervals displayed in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get the time series array.Initialize a variable, n_steps, to get the mean and standard deviation.Get the under and above lines for confidence intervals.Plot the mean line using plot() method.Use fill_between() method to get the confidence interval.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True time_series_array = np.sin(np.linspace           ... Read More

Plot Watermark Image in Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:59:44

1K+ Views

To plot a watermark image in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Return a sample data file using get_sample_data() method.Create a figure and a set of subplots.Plot the data points using plot() method, with alpha=0.7 and marker face color mfc="orange".Add a non-resampled image to the figure.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.cbook as cbook import matplotlib.image as image import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True with cbook.get_sample_data('logo2.png') as file: im = image.imread(file) fig, ax = ... Read More

Different X and Y Scales in Zoomed Inset in Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:59:19

1K+ Views

To show different X and Y scales in zoomed inset in Matplotlib, we can use inset_axes() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Add a subplot to the current figure.Plot x and y data points using plot() method.Create an inset axes with a given width and height.Set different x and y scales.Draw a box to mark the location of an area represented by an inset axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1.inset_locator import mark_inset, inset_axes plt.rcParams["figure.figsize"] = [7.50, ... Read More

Write Your Own LaTeX Preamble in Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:58:50

295 Views

To write your own LaTeX preamble 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 random data points using numpy.Plot x and y data points using plot() method. Use LaTex formatting for the label.label="$y=e^{x}$"Place a legend on the figure using legend() 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(-10, 10, 100) y = np.exp(x) plt.plot(x, y, color='red', label="$y=e^{x}$") plt.legend(loc='upper right') plt.show()OutputRead More

Plot y1 and x as a Single Graph in Python

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:58:28

2K+ Views

To plot y=1/x as a single graph in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create data points using numpy.Plot x and 1/x data points using plot() method.Place a legend on the figure.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(-10, 10, 101) plt.plot(x, 1/x, label='$f(x)=\frac{1}{x}$') plt.legend(loc='upper left') plt.show()Output

Change Separation Between Tick Labels and Axis Labels in Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:58:02

22K+ Views

To change the separation between tick labels and axis labels in Matplotlib, we can use labelpad in xlabel() method.StepsSet the figure size and adjust the padding between and around the subplots.Plot data points of a list using plot() method.Set the ticks on the axes.Set X and Y axes margins to 0.Set the X-axis label with labelpad.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([1, 2, 3, 4, 5]) plt.xticks([1, 2, 3, 4, 5]) plt.margins(x=0, y=0) plt.xlabel("X-axis", labelpad=7) plt.show()Output

Modify Font Size in Matplotlib Venn Diagram

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:57:34

2K+ Views

To modify the font size in Matplotlib-venn, we can use set_fontsize() method.StepsSet the figure size and adjust the padding between and around the subplots.Create three sets for Venn diagram.Plot a 3-set area-weighted Venn diagram.To set the set_labels and subset_labels fontsize, we can use set_fontsize() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt from matplotlib_venn import venn3 plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True set1 = {'a', 'b', 'c', 'd'} set2 = {'a', 'b', 'e'} set3 = {'a', 'd', 'f'} out = venn3([set1, set2, set3], ('Set1', 'Set2', 'Set3')) for text in out.set_labels:   ... Read More

Plot Non-Square Seaborn Jointplot or JointGrid in Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:57:10

731 Views

To plot a non-square Seaborn jointplot or jointgrid, we can use set_figwidth() and set_figheight() methods.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a dataframe with two columns.Use jointplot() method to plot the jointplot.To make it non-square, we can set the figure width and height.To display the figure, use show() method.Exampleimport seaborn as sns import numpy as np from matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True X = np.random.randn(1000, ) Y = 0.2 * np.random.randn(1000) + 0.5 ... Read More

Add Legend on Seaborn FacetGrid Bar Plot Using Matplotlib

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:56:43

5K+ Views

StepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe with col1 columns.Multi-plot grid for plotting conditional relationships.Use map_dataframe(). This method is suitable for plotting with functions that accept a long-form DataFrame as a 'data' keyword argument and access the data in that DataFrame using string variable names.Add a legend to the plot().To display the figure, use show() method.Exampleimport pandas as pd import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'col1': [3, 7, 8]}) g = sns.FacetGrid(df, col="col1", hue="col1") g.map_dataframe(sns.scatterplot) g.set_axis_labels("X", ... Read More

Advertisements