Data Visualization Articles

Page 33 of 68

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 751 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 390 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 198 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

How to change the datetime tick label frequency for Matplotlib plots?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Jun-2021 6K+ Views

To change the datetime tick label frequency for Matplotlib plots, we can create a dataframe and plot them in some date rangeStepsSet the figure size and adjust the padding between and around the subplots.To make potentially heterogeneous tabular data, use Pandas dataframe.Plot the dataframe using plot() method.Set X-axis major locator, i.e., ticks.Set X-axis major formatter, i.e., tick labels.Use autofmt_xdate(). Date ticklabels often overlap, so it is useful to rotate them and right align them.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates plt.rcParams["figure.figsize"] = [7.50, ...

Read More

How to add a legend to a Matplotlib pie chart?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 16-Jun-2021 8K+ Views

To add a legend to a Matplotlib pie chart, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of labels, colors, and sizes.Use pie() method to get patches and texts with colors and sizes.Place a legend on the plot with patches and labels.Set equal scaling (i.e., make circles circular) by changing the axis limits.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True labels = ['Walk', 'Talk', 'Sleep', 'Work'] sizes = [23, 45, 12, 20] colors = ['red', 'blue', ...

Read More
Showing 321–330 of 680 articles
« Prev 1 31 32 33 34 35 68 Next »
Advertisements