Rishikesh Kumar Rishi has Published 1162 Articles

Matplotlib legends in subplot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 26-Oct-2023 03:33:10

22K+ Views

To add legends in a subplot, we can take the following Steps −Using numpy, create points for x, y1, y2 and y3.Create a figure and a set of subplots, using the subplots() method, considering 3 subplots.Plot the curve on all the subplots(3), with different labels, colors. To place the legend ... Read More

How to plot multiple graphs in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 22-Oct-2023 13:20:10

20K+ Views

To plot multiple graphs in matplotlib, we will use the following steps −StepsCreate x, y1 and y2 data points using numpy.Add a subplot to the current figure at index 1.Plot curve 1 using x and y1.Add a subplot to the current figure at index 2.Plot curve 2 using x and y2.To display the figure, ... Read More

How to change the color of the axis, ticks and labels for a plot in matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-Oct-2023 03:00:48

25K+ Views

We can change the color of the axis, ticks and labels, using ax.spines['left'].set_color('red') and ax.spines['top'].set_color('red') statements. To change the color of the axis, ticks, and labels for a plot in matplotlib, we can take the following steps −Create a new figure, or activate an existing figure, using plt.figure().Add an axis ... Read More

How to save Pandas data into Excel multiple sheets?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 04-Oct-2023 21:36:25

21K+ Views

To save Pandas DataFrames into multiple excel sheets, we can use the pd.ExcelWriter() method. Make sure you have the openpyxl package installed before using ExcelWriter().StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df1.Print the input DataFrame, df1.Create another DataFrame, df2, and print it.Use ExcelWriter() method to write the given formatted ... Read More

How to write text in subscript in the axis labels and the legend using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 04-Oct-2023 21:14:44

27K+ Views

To write text in subscript in the axis labels and the legend, we can take the following steps −Create x and y data points using NumPy.Plot x and y data points with a super subscript texts label.Use xlabel and ylabel with subscripts in the text.Use the legend() method to place a legend ... Read More

How to clear the memory completely of all Matplotlib plots?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 14-Sep-2023 15:47:36

29K+ Views

Using the following methods, we can clear the memory occupied by Matplotlib plots.plt.figure() - Create a new figure or activate an existing figure.plt.figure().close() -  Close a figure window.close() by itself closes the current figureclose(h), where h is a Figure instance, closes that figureclose(num) closes the figure number, numclose(name), where name is ... Read More

Plot a bar using matplotlib using a dictionary

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 14-Sep-2023 13:55:39

25K+ Views

First, we can define our dictionary and then, convert that dictionary into keys and values. Finally, we can use the data to plot a bar chart.StepsCreate a dictionary, i.e., data, where milk and water are the keys.Get the list of keys of the dictionary.Get the list of values of the ... Read More

How to get a value from the cell of a Pandas DataFrame?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 14-Sep-2023 01:23:02

30K+ Views

To get a value from the cell of a DataFrame, we can use the index and col variables.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Initialize the index variable.Initialize the col variable.Get the cell value corresponding to index and col variable.Print the cell value.Example Live Demoimport pandas ... Read More

How to select all columns except one in a Pandas DataFrame?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 13-Sep-2023 15:54:47

29K+ Views

To select all columns except one column in Pandas DataFrame, we can use df.loc[:, df.columns != ].StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Initialize a variable col with column name that you want to exclude.Use df.loc[:, df.columns != col] to create another DataFrame excluding a ... Read More

Plot multiple boxplots in one graph in Pandas or Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 13-Sep-2023 13:13:47

29K+ Views

To plot multiple boxplots in one graph in Pandas or Matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas data frame with two columns.Plot the data frame using plot() method, with kind='boxplot'.To display the figure, use show() ... Read More

1 2 3 4 5 ... 117 Next
Advertisements