Found 10476 Articles for Python

How to get coordinates from the contour in matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:32:44

5K+ Views

To get coordinates from the contour in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create lists of x, y and m with data points.Use plt.contour(x, y, m) to create a contour plot with x, y and m data points.Get the contour collections instance.Get the path of the collections, and print the vertices or coordinates of the contour.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 x = [1, 2, 3, 4] y = [1, 2, 3, 4] m ... Read More

How to sort bars in increasing order in a bar chart in matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:30:28

21K+ Views

To sort bars in increasing order in a bar chart in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a data frame, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Add a subplot to the current figure.Make a bar plot with the dataframe, df.Add a subplot to the current figure.Make a df_sorted by a column marks.Make a bar plot with df_sorted.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame( ... Read More

How to remove random unwanted space in LaTeX-style maths in matplotlib plot?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:27:50

9K+ Views

LaTeX ignores the spaces you type and uses spacing the way it's done in mathematics texts. You can use the following four commands in case you want a different spacing style\; – thick space\: – medium space\, – a thin space\! – a negative thin spaceTo remove random unwanted space in LaTeX-style maths in matplotlib plot, we can use "\!" which will reduce the extra spacing.Let's take an example and understand how it works. We will have two sub-plots and then we will add a complex mathematical equation (using LaTex) in a textbox in both the sub-plots. However, we will ... Read More

How to get pixel coordinates for Matplotlib-generated scatterplot?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:19:45

2K+ Views

To get pixel coordinates for matplotlib-generated scatterplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable "n" to hold the number of sample data.Create a figure and a set of subplots.Make a scatter plot.Get the x and y data points using get_data() method.Get the pixel value of the plot.Get the pixel tranformed data.Get the figure width and height in points or pixelsPrint the x and y pixels value.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

How to animate text in Matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:10:57

2K+ Views

To animate text in matplotlib, we can take the following steps −Import "animation" package from matplotlib.Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Initialize a variable "text" to hold a string.Add text to the axes at x=0.20 and y=0.50.Make a list of colors.Make an animation by repeatedly calling a function *animate*, where size of text is increased and color is changed.To display the figure, use show() method.Examplefrom matplotlib import animation import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = ... Read More

How to make a grouped boxplot graph in matplotlib?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:12:54

3K+ Views

To make a grouped boxplot graph in matplotlib, we can take the following steps −Import matplotlib.pyplot and seaborn.Set the figure size and adjust the padding between and around the subplots.Load an example Seaborn dataset from the online repository.Make a boxplot with male and female group in a single day.To display the figure, use show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Import a Seaborn dataset data = sns.load_dataset('tips') # Create a grouped boxplot sns.boxplot(x=data['day'], y=data['total_bill'], hue=data['sex']) plt.show()OutputIt will produce the following ... Read More

How to plot a rainbow cricle in matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:07:00

880 Views

To plot a rainbow circles in Matplotlib, 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.Set the X and Y axes scale.Make a list of rainbow colors.Create a true circle at (0, 0).Add a circle instance 'c' to the figure.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 5.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() plt.axis("equal") ax.set(xlim=(-10, 10), ylim=(-10, 10)) for i in range(0, 7): rainbow = ['violet', 'indigo', 'blue', 'green', ... Read More

How to plot thousands of circles quickly in Matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:05:11

2K+ Views

To plot thousands of circles quickly in Matplotlib, we will have to use matplotlib.collections. In this case, we will use CircleCollection.StepsImport the collections package from matplotlib along with pyplot and numpy.Set the figure size and adjust the padding between and around the subplots.Initialize variables "num" for number of small circles and "sizes" for sizes of circles.Create a list of circle patches.Add circle patch artist on the current axis.Set the margins of the axes.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.collections as mc plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True num ... Read More

Plotting multiple dataframes using Pandas functionality

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:02:53

26K+ Views

To plot multiple dataframes using Pandas functionality, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create two Pandas dataframes, df1 and df2, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot df1 and df2 using plot() method.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df1 = pd.DataFrame( dict( name=['John', 'James', 'Stephen', 'Kandy'], age=[23, 45, 12, 34] ) ... Read More

How to plot a time series graph using Seaborn or Plotly?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 05:58:00

3K+ Views

To plot a time series graph using Seaborn or Plotly, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe, df, to hold a date_time series "time" and another variable data, speed.Make a Seaborn line plot with the data, "time" and "speed"Rotate the tick params by 45.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt import pandas as pd import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame( dict( ... Read More

Advertisements