Found 784 Articles for Data Visualization

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

170 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

Animation using Matplotlib with subplots and ArtistAnimation

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:41:05

2K+ Views

To animate using Matplotlib with subplots and ArtistAnimation, 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.Create a user-defined function, Init, to draw a clear frame.Use FuncAnimation to make an animation by repeatedly calling a function *func*.Define an animate function to update the data points in FuncArtist class.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() xdata, ydata = [], [] ln, ... Read More

How to decrease colorbar width in Matplotlib?

Rishikesh Kumar Rishi
Updated on 17-Jun-2021 11:40:30

2K+ Views

To decrease colorbar width in Matplotlib, we can use shrink in colorbar() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a random data using numpy.Display the data as an image, i.e., on a 2D regular raster, with data.Create a colorbar for a ScalarMappable instance, im.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 data = np.random.rand(5, 5) im = plt.imshow(data, cmap="YlOrBr") plt.colorbar(im, shrink=0.50) plt.show()Output

Advertisements