- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 784 Articles for Data Visualization
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
80 Views
To force errorbars to render last with 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 using figure() method.Get the current axis using gca() method.Plot the list of linesPlot y versus x as lines and/or markers with attached errorbars.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = plt.gca() [ax.plot(np.random.rand(10)) for j in range(10)] ax.errorbar(range(10), np.random.rand(10), yerr=.3 * np.random.rand(10)) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
184 Views
Matplotlib provides a number of colormaps, and others can be added using :func:'~matplotlib.cm.register_cmap'. This function documents the built-in colormaps, and will also return a list of all registered colormaps, if called.Examplefrom matplotlib import pyplot as plt cmaps = plt.colormaps() print("Possible color maps are: ") for item in cmaps: print(item)OutputAccent Accent_r Blues ... ... ... viridis_r winter winter_r
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To plot multiple time-series data frames into a single plot using Pandas, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas data frame with time series.Set the time series index for plot.Plot rupees and dollor on the plot.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt, dates plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(date=list(pd.date_range("2021-01-01", periods=10)), rupees=np.linspace(1, 10, 10), dollar=np.linspace(10, 20, 10))) df.set_index(pd.to_datetime(df.date), drop=True).plot() df = df.set_index(pd.to_datetime(df.date), drop=True) df.rupees.plot(grid=True, label="rupees", legend=True) df.dollar.plot(secondary_y=True, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
864 Views
To make several legend keys to the same entry in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Plot line1 and line2 using plot() method.Use legend() method to place a legend over the plot with numpoints=1To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.legend_handler import HandlerTuple plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True p1, = plt.plot([1, 2.5, 3], 'r-d') p2, = plt.plot([3, 2, 1], 'k-o') l = plt.legend([(p1, p2)], ['Two keys'], numpoints=1, handler_map={tuple: andlerTuple(ndivide=None)}) plt.show()OutputRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To remove horizontal lines in an image, we can take the following steps −Read a local image.Convert the image from one color space to another.Apply a fixed-level threshold to each array element.Get a structuring element of the specified size and shape for morphological operations.Perform advanced morphological transformations.Find contours in a binary image.Repeat step 4 with different kernel size.Repeat step 5 with a new kernel from step 7.Show the resultant image.Exampleimport cv2 image = cv2.imread('input_image.png') cv2.imshow('source_image', image) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25, 1)) detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
3K+ Views
To specify the line width of the legend frame in Matplotlib, we can use set_linewidth() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots using subplots() method.Plot x and y using plot() method.Place a legend on the figure and get the legend instance.Get the lines and set the line width in the legend frame.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(-5, 5, 100) y ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
4K+ Views
To plot a Pandas multi-index data frame with all xticks, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create index value with 1000 smaples data.Make a one-dimensional ndarray with axis labels.Get the mean value of the series.Plot g dataframe.Set the ticks and ticklabel on the current axesTo display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True idx = pd.date_range("2020-01-01", periods=1000) val = np.random.rand(1000) s = pd.Series(val, idx) g = s.groupby([s.index.year, s.index.month]).mean() ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
597 Views
We can save the current figure in the local machine and can display it.StepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Plot x and y data points using plot() method.Save the figure using savefig() 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(-np.pi, np.pi, 100) plt.plot(x, np.sin(x) * x, c='red') plt.savefig("myimage.png")OutputWhen we execute the code, it will save the following image as "myimage.png" in the project directoryRead More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To draw a line (i.e., arrow) outside of an axis, we can use annotate() method, StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Clear the current figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.Use annotate() method to place a line outside the axes.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(1) fig.clf() ax = fig.add_subplot(1, 1, 1) ax.annotate('', xy=(0, -0.1), xycoords='axes fraction', xytext=(1, -0.1), ... Read More
![Rishikesh Kumar Rishi](https://www.tutorialspoint.com/assets/profiles/318007/profile/60_254496-1615815423.jpg)
2K+ Views
To animate the colorbar 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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Instantiate Divider based on the pre-existing axes, i.e., ax object and return a new axis locator for the specified cell.Create an axes at the given *position* with the same height (or width) of the main axes.Create random data using numpy.Use imshow() method to plot random data.Set the title of the plot.Instantiate the list of colormaps.To animate the ... Read More