Found 1034 Articles for Matplotlib

How can I make Matplotlib.pyplot stop forcing the style of my markers?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:43:49

98 Views

To make matplotlib.pyplot stop forcing the style of markers, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random x and y data points using numpy.Plot x and y data points using plot() method, with "r*" marker with markersize=10.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.random.rand(20) y = np.random.rand(20) plt.plot(x, y, 'r*', markersize=10) plt.show()Output

Setting the limits on a colorbar of a contour plot in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:43:15

10K+ Views

To set the limits on a colorbar of a countour plot 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.Get the data using x and y.Get the coordinate matrices from the coordinate vectors.Initialize vmin and vmax to set the limits on a colorbar of a contour plot in matplotlib.Plot contours using contourf() method.Make the colorbar using scalar mappable within the range of vmin and vmax.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np from ... Read More

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

414 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

843 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

889 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

Advertisements