Found 784 Articles for Data Visualization

How can I make the xtick labels of a plot be simple drawings using Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:42:38

92 Views

To make xtick labels of a plot be simple drawings using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize the y position of simple drawings.Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot()method.Plot a line using plot() method.Set the X-axis ticks using set_ticks() method.Set empty tick labels.Add circles and rectangles patches using add_patch() method. Instantiate Circle() and Rectangle() class.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import matplotlib.patches as patches ... Read More

Indicating the statistically significant difference in bar graph (Matplotlib)

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:41:30

413 Views

To indicate the statistically significant difference in bar graph, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create means, std, index, width and labels data points.Create a figure and a set of subplots using subplots() method.Make a bar plot using bar() method.Plot Y versus X as lines and/or markers with attached errorbars.Scale the Y-axis.Get or set the current tick locations and labels of the X-axis.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 means = (5, 15, ... Read More

How to show node name in Matplotlib graphs using networkx?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:40:50

1K+ Views

To show node name in graphs using networkx, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a graph with edges, name, or graph attributes.Add multiple nodes using add_nodes_from() method.Add all the edges using add_edge_from() method.Draw the graph G with Matplotlib using draw() method. Set with_labels to True.To display the graph, we can use show() method.Exampleimport matplotlib.pylab as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True G = nx.DiGraph() G.add_nodes_from([1, 2, 3, 4]) G.add_edges_from([(1, 2), (2, 1), (2, 3), (1, 4), (3, 4)]) nx.draw(G, ... Read More

How to add a title on Seaborn lmplot?

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:40:12

838 Views

To add a title on Seaborn Implot, we can take the following steps−Set the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with two columns, X-Axis and Y-AxisUse implot() method.Get the current axis using gca() method.To display the figure, use show() method.Exampleimport pandas import matplotlib.pylab as plt import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pandas.DataFrame({"X-Axis": [np.random.randint(10) for i in range(10)], "Y-Axis": [i for i in range(10)]}) bar_plot = sns.lmplot(x='X-Axis', y='Y-Axis', data=df, height=3.5) ax = plt.gca() ax.set_title("Random Data Implot") ... Read More

Transparency for Poly3DCollection plot in Matplotlib

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:38:31

634 Views

To plot a transparent Poly3DCollection plot in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplotsCreate a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement with projection=3d.Create x, y and z data points.Make a list of vertices.Convert x, y and z data points into a zipped list of tuples.Get a list of instance of Poly3d.Add a 3D collection object to the plot using add_collection3d() method.Turn off the axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt ... Read More

How to install Matplotlib on Mac 10.7 in virtualenv?

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:36:37

582 Views

To install Matplotlib in virtualenv, we can take the following steps in terminal −vritualenv source env/bin/activatepip install matplotlibpip freeze > requirements.txtcat requirements.txt (To see the Matplotlib details)

Plot two horizontal bar charts sharing the same Y-axis in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:34:54

888 Views

To plot two horizontal bar charts sharing the same Y-axis, we can use sharey=ax1 in subplot() method and for horizontal bar, we can use barh() method.StepsCreate lists for data points.Create a new figure or activate an existing figure using figure() methodAdd a subplot to the current figure using subplot() method, at index=1.Plot horizontal bar on axis 1 using barh() method.Add a subplot to the current figure using subplot() method, at index=2. Share the Yaxis of axis 1.Plot the horizontal bar on axis 2.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, ... Read More

How to remove a specific line or curve in Matplotlib?

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:32:58

7K+ Views

To remove a specific line or curve 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.Pop the second line and remove it.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, image as mimg plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True line_1 = plt.plot([1, 2, 3]) line_2 = plt.plot([2, 4, 6]) line = line_2.pop(0) line.remove() plt.show()Output

Set a colormap of an image in Matplotlib

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:31:33

2K+ Views

To set a colormap of an image, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Read an image from a file into an array.Pick one channel of your data.Display the data as an image, i.e., on a 2D regular raster with "hot" colormapTurn off the axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, image as mimg plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = mimg.imread('bird.jpg') lum_img = img[:, :, 0] plt.imshow(lum_img, cmap="hot") plt.axis('off') plt.show()OutputRead More

Plotting at full resolution with matplotlib.pyplot, imshow() and savefig()

Rishikesh Kumar Rishi
Updated on 05-Jun-2021 08:30:25

4K+ Views

To plot at full resolution with matplotlib.pyplot, imshow() and savefig(), we can keep the dpi value from 600 to 1200.StepsSet the figure size and adjust the padding between and around the subplots.Set random values in a given shape.Display the data as an image, i.e., on a 2D regular rasterSave the figure with 1200 dpi.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 data = np.random.rand(5, 5) plt.imshow(data, cmap="plasma") plt.savefig("myimage.eps", dpi=1200) plt.show()Output

Advertisements