Found 784 Articles for Data Visualization

How can one modify the outline color of a node in networkx using Matplotlib?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:30:46

2K+ Views

To modify the outline color of a node in networkx, we can use set_edgecolor() method.StepsCreate a Pandas dataframe with from and to keys.Return a graph from Pandas DataFrame containing an edge list.Get the position of the nodes.Draw the nodes of the graph using draw_networkx_nodes().Set the outline color of the nodes using set_edgecolor().To display the figure, use show() method.Examplefrom networkx import * import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'from': ['A', 'B', 'C', 'A'], 'to': ['D', 'A', 'E', 'C']}) G = nx.from_pandas_edgelist(df, 'from', 'to') pos = spring_layout(G) nodes = draw_networkx_nodes(G, pos) ... Read More

How do I change the font size of ticks of matplotlib.pyplot.colorbar.ColorbarBase?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:31:08

14K+ Views

To change the font size of ticks of a colorbar, we can take the following steps−Create a random data set of 5☓5 dimension.Display the data as an image, i.e., on a 2D regular raster.Create a colorbar with a scalar mappable object image.Initialize a variable for fontsize to change the tick size of the colorbar.Use axis tick_params() method to set the tick size of the colorbar.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 data = np.random.rand(5, 5) im = plt.imshow(data, interpolation="nearest", cmap="copper") cbar = plt.colorbar(im) tick_font_size ... Read More

How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:24:35

2K+ Views

To set Step on X-axis in a figure in Matplotlib Python, we can take the following Steps −StepsCreate a list of data points, x.Add a subplot to the current figure using subplot() method.Set xticks and ticklabels with rotation=45.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 2, 3, 4] y = [1.2, 1.9, 3.1, 4.2] plt.plot(x,y) ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_xticklabels(["one", "two", "three", "four"], rotation=45) plt.show()Output

How to read an image in Python OpenCV?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:24:17

808 Views

To read an image in Python OpenCV, we can take the following Steps −Load an image from a file.Display the image in the specified window.Wait for a pressed key.Destroy all of the HighGUI windows.Exampleimport cv2 img = cv2.imread("baseball.png", cv2.IMREAD_COLOR) cv2.imshow("baseball", img) cv2.waitKey(0) cv2.destroyAllWindows()Output

How to change the figsize for matshow() in Jupyter notebook using Matplotlib?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:31:37

727 Views

To change the figsize for mathshow, we can use figsize in figure method argument and use fignum in matshow() method.StepsCreate a new figure or activate an existing figure using figure() method.Create a dataframe using Pandas.Use matshow() method to display an array as a matrix in a new figure window.The argument fignum can take the values None, int, or FalseIf *None*, create a new figure window with automatic numbering.If a nonzero integer, draw into the figure with the given number. Create one, if it does not exist.If 0, use the current axes (or create one if it does not exist).To display ... Read More

How to get the default blue colour of matplotlib.pyplot.scatter?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:23:40

5K+ Views

The default color of a scatter point is blue. To get the default blue color of matplotlib scatter point, we can annotate them using annotate() method.StepsCreate a figure and a set of subplots using subplots() method.Plot a scatter point at (-1, 1) location.Add some label for that point.Plot a scatter point at (-0.9, 1) location.Add some label for that point.Plot a scatter point at (1.9, 1) location.Add some label for that point.Scale the x and y axes using xlim and ylim method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More

How to set same color for markers and lines in a Matplotlib plot loop?

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:23:17

1K+ Views

To set the same color for markers and lines in a matplotlib, we can take the following Steps −Initialize m, n and x data points using numpy.Create a new figure or activate an existing figure using figure() method.Clear the figure using clf() method.Add a subplot to the current figure using subplot() method.Get a marker from a iterable marker type.Iterate a range from 1 to n.Plot the lines and markers in the loop using plot() method with the same marker and colors for a line.To display the figure, use show() method.Exampleimport numpy as np import itertools from matplotlib import pyplot as ... Read More

Plot a rectangle with an edgecolor in Matplotlib

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:22:52

1K+ Views

To put edgecolor of a rectangle in matplotlib, we can take the following Steps −Create a new figure or activate an existing figure using figure() method.Add a subplot method to the current axis.Create a rectangle instance using Rectangle() class with an edgecolor and linewidth of the edge.Add a rectangle path on the plot.To place the text in the rectangle, we can use text() method.Scale x and y axes using xlim() and ylim() methods.To display the figure, use show() method.Exampleimport matplotlib from matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111) ... Read More

Plotting a horizontal line on multiple subplots in Python using pyplot

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:12:33

7K+ Views

To plot a horizontal line on multiple subplots in Python, we can use subplots to get multiple axes and axhline() method to draw a horizontal line.StepsCreate a figure and a set of subplots. Here, we will create 3 subplots.Use axhline() method to draw horizontal lines on each axis.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt fig, (ax1, ax2, ax3) = plt.subplots(3) plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ax1.axhline(y=0.5, xmin=0, xmax=3, c="black", linewidth=2, zorder=0) ax2.axhline(y=0.5, xmin=0, xmax=3, c="red", linewidth=3, zorder=0) ax3.axhline(y=0.5, xmin=0, xmax=3, c="yellow", linewidth=4, zorder=0) plt.show()OutputRead More

Overlay an image segmentation with Numpy and Matplotlib

Rishikesh Kumar Rishi
Updated on 15-May-2021 12:12:02

2K+ Views

To overlay an image segmentation with numpy, we can take the following Steps −Make a masked array of 10×10 dimension.Update the masked array with 1 for some region.Make image data using numpy.Mask an array where a condition is met, to get the masked data.Create a new figure or activate an existing figure using figure() mrthod.Use imshow() method to display data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True mask = np.zeros((10, 10)) mask[3:-3, 3:-3] = 1 im ... Read More

Advertisements