Found 1034 Articles for Matplotlib

How to plot a time series array, with confidence intervals displayed 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

How to plot a 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

995 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

How to write your own LaTeX preamble in Matplotlib?

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

171 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

How to plot y=1/x as a single graph in Python?

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

1K+ 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

How to change the separation between tick labels and axis labels in Matplotlib?

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

19K+ 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

How to modify the font size in Matplotlib-venn?

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

1K+ 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

How to plot a non-square Seaborn jointplot or JointGrid? (Matplotlib)

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

581 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

How to add a legend on Seaborn facetgrid bar plot using Matplotlib?

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

4K+ 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

How to retrieve the list of supported file formats for Matplotlib savefig()function?

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

253 Views

To retrieve the list of supported file formats for matplotlib savefig() function, we can use get_supported_filetypes().StepsFirst get the current figure.Set the canvas that contains the figure.Use get_supported_filetypes() method.Iterate the file type items.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt fs = plt.gcf().canvas.get_supported_filetypes() for key, val in fs.items(): print(key, ":", val)Outputeps : Encapsulated Postscript jpg : Joint Photographic Experts Group jpeg : Joint Photographic Experts Group pdf : Portable Document Format pgf : PGF code for LaTeX png : Portable Network Graphics ps : Postscript raw : Raw RGBA bitmap rgba : Raw RGBA bitmap ... Read More

Advertisements