Data Structure
 Networking
 RDBMS
 Operating System
 Java
 MS Excel
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP
- Selected Reading
 - UPSC IAS Exams Notes
 - Developer's Best Practices
 - Questions and Answers
 - Effective Resume Writing
 - HR Interview Questions
 - Computer Glossary
 - Who is Who
 
Server Side Programming Articles - Page 1020 of 2650
 
			
			410 Views
To plot Pandas data frames in Pie charts using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a dataframe of two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot the dataframe with activities index using pie() methodTo 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({'activities': ['sleep', 'exercise', 'work', 'study'], 'hours': [8, 1, 9, 6]}) df.set_index('activities').plot.pie(y='hours', legend=False, autopct='%1.1f%%') plt.show()Output
 
			
			18K+ Views
To force matplotlib to show the values on X-axis as integers, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create two lists, x and y, of data points.Plot x and y using plot() method.Make a new list for only integers tick on X-axis. Use math.floor() and math.ceil() to remove the decimals and include only integers in the list.Set x and y labels.Set the title of the figure.To display the figure, use show() method.Exampleimport math from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True y ... Read More
 
			
			9K+ Views
To plot certain rows of a Pandas dataframe, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas data frame, df. It should be a two-dimensional, size-mutable, potentially heterogeneous tabular data.Make rows of Pandas plot. Use iloc() function to slice the df and print specific rows.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.randn(10, 5), columns=list('abcde')) df.iloc[0:6].plot(y='e') print(df.iloc[0:6]) # plt.show()OutputWe have 10 rows in ... Read More
 
			
			2K+ Views
To move X-axis in Matplotlib during real-time plot, 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 x and y data points using numpy.Plot x and y data points using plot() method.Make an animation by repeatedly calling a function *animate* that moves the X-axis during real-time plot.To display the figure, use show() method.Exampleimport matplotlib.pylab as plt import matplotlib.animation as animation import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.linspace(0, 15, 100) ... Read More
 
			
			4K+ Views
To update a bar plot dynamically in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Make a list of data points and colors.Plot the bars with data and colors, using bar() method.Using FuncAnimation() class, make an animation by repeatedly calling a function, animation, that sets the height of the bar and facecolor of the bars.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import animation as animation, pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More
 
			
			120 Views
To draw more type of lines 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 data points using numpy.Plot x and y data points using plot() method, with an array of dashes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) y = np.sin(x) plt.plot(x, y, dashes=[1, 1, 2, 1, 3], linewidth=7, color='red') plt.show()Output
 
			
			2K+ Views
To move the legend to outside of a Seaborn scatterplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with three coulmns, column1, column2 and column3.Draw a scatterplot with possibility of several semantic groupings.To place the legend outside the plot, use bbox_to_anchor in legend() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import pandas as pd import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(col1=[2, 1, 4], ... Read More
 
			
			3K+ Views
To change the marker size with pandas.plot(), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe with three columns, col1, col2 and col3.Use pandas.plot() with marker="*" and markersize=15.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame([[2, 1, 4], [5, 2, 1], [4, 0, 1]], columns=['col1', 'col2', 'col3']) df.plot(marker="*", markersize=15) plt.show()Output
 
			
			1K+ Views
To set timeout to pyplot.show() in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new backend-specific subclass of '.Timer'.Add a callback function that will be called whenever one of the plt.close() properties changes.Plot a list of data points.Start the timer.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 fig = plt.figure() # set the timer interval 5000 milliseconds timer = fig.canvas.new_timer(interval = 5000) timer.add_callback(plt.close) plt.plot([1, 2, 3, 4, 5]) plt.ylabel('Y-axis Data') timer.start() plt.show()OutputThe ... Read More
 
			
			860 Views
To pass arguments to animation.FuncAnimation() for a contour plot in Matplotlib in Python, we can take the following steps −Create a random data of 10☓10 dimension.Create a figure and a set of subplots using subplots() method.Make an animation by repeatedly calling a function *func* using FuncAnimation() classTo update the contour value in the function, we can define a method animate() that can be used in FuncAnimation() class.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.randn(800).reshape(10, 10, 8) fig, ax ... Read More