Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 41 of 102

How to plot a time series array, with confidence intervals displayed in Python? (Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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

Read More

How to modify the font size in Matplotlib-venn?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 756 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
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 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

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 398 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

How to make an arrow that loops in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 206 Views

To make an arrow that loops in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.To make an arrow loop in matplotlib, we can use make_loop() method.Make a wedge instance with center, radius, theta1, theta2 and width.To put the arrow top of the loop, use PathCollection.Add patch collection to the current axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches, collections plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def make_loop(center, radius, theta1=-30, theta2=180):    rwidth = 0.02    ring = patches.Wedge(center, radius, theta1, ...

Read More
Showing 401–410 of 1,016 articles
« Prev 1 39 40 41 42 43 102 Next »
Advertisements