
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
Found 10476 Articles for Python

13K+ Views
To make a multiline plot from .CSV file in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of columns to fetch the data from a .CSV file. Make sure the names match with the column names used in the .CSV file.Read the data from the .CSV file.Plot the lines using df.plot() method.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Make a list of ... Read More

9K+ Views
To plot two different arrays of different lengths in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create y1, x1, y2 and x2 data points using numpy with different array lengths.Plot x1, y1 and x2, y2 data points using plot() method.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"] = True y1 = (np.random.random(100) - 0.5).cumsum() y2 = y1.reshape(-1, 10).mean(axis=1) x1 = np.linspace(0, 1, 100) x2 = np.linspace(0, 1, 10) plt.plot(x1, y1) plt.plot(x2, y2) ... Read More

10K+ Views
To shift a graph along the X-axis 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 the x and y data points for the original curve.Plot the shifted graph, in the range of (1, 1+len(y)) with y data points.Place a legend on the figure.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, ... Read More

7K+ Views
To set xticks and yticks with imshow() plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get the current axis.Create a random dataset.Display the data as an image, i.e., on a 2D regular raster.Set x and y ticks using set_xticks() and set_yticks() method.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"] = True ax = plt.gca() data = np.random.rand(6, 6) ax.imshow(data) # Set xticks and yticks ax.set_xticks([1, 2, 3, 4, 5]) ax.set_yticks([1, 2, 3, 4, 5]) ... Read More

3K+ Views
To remove white border when using subplot and imshow(), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data points using numpy.Get the size of the data.Set the figure sizes in inches.Get the axes instance that contains most of the figure element.Turn off the axes.Add axes to the figure.Display the data as an image, i.e., on a 2D regular raster.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"] = True data = np.random.randint(0, 50, (50, 50)) sizes ... Read More

5K+ Views
To show tick labels on top of a matplotlib plot, we can use the set_tick_params() method with labeltop=True.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Show the tick labels at the top of the plot. Use set_tick_parama() with labeltop=True.Hide the tick labels of the bottom axis of plot. Use set_tick_parama() with labeltop=False.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create subplots fig, ax = plt.subplots(1, 1) # Show the ... Read More

2K+ Views
To pass a matplotlib object through a function; as Axis, Axes or figure, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.In plot() method, plot x and y data points at axes ax.In profile() method, create a figure and a set of subplots. Iterate the axes and pass in plot() method to plot the figure.Call the profile() method with 3 rows and 4 columns.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def plot(ax, ... Read More

2K+ Views
To label bubble charts/scatter plot with column from Pandas dataframe, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a data frame, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a scatter plot with df.Annotate each data point with a text.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a dataframe df = pd.DataFrame( dict( x=[1, 3, 2, ... Read More

532 Views
To plot multicolor line if X-axis is datetime index of Pandas, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create d, y and s data points using numpy.Create a figure and a set of subplots.Get xval, p and s data point using numpy.Get the line collection instance with hot colormap and s data points.Set major and minor axes locator and set axes formatter.Autoscale the view limits using the data limits.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt, dates as mdates, collections as ... Read More

313 Views
To find rolling mean, we will use the apply() function in Pandas. At first, let us import the required library −import pandas as pdCreate a DataFrame with 2 columns. One is an int column −dataFrame = pd.DataFrame( { "Car": ['Tesla', 'Mercedes', 'Tesla', 'Mustang', 'Mercedes', 'Mustang'], "Reg_Price": [5000, 1500, 6500, 8000, 9000, 6000] } )Group using GroupBy and find the Rolling Mean using apply() −dataFrame.groupby("Car")["Reg_Price"].apply( lambda x: x.rolling(center=False, window=2).mean()) ExampleFollowing is the code −import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { ... Read More