Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 39 of 102

How to check that pylab backend of Matplotlib runs inline?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 401 Views

To check that pylab/pyplot backend of Matplotlib runs inline, we can use get_backend() method.The method returns the name of the current backend.Exampleimport matplotlib inline = matplotlib.get_backend() print("Backend: ", inline)OutputBackend: Qt5Agg

Read More

How can I attach a pyplot function to a figure instance? (Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 247 Views

To attach a pyplot function to a figure instance, we can use figure() method and add an axes to it.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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Set a title to this axis using set_title() method.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() ax = fig.add_subplot() ax.set_title("My Title!") plt.show()Output

Read More

How to add legend to imshow() in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 5K+ Views

To add legend to imshow() in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data using numpy.Initialize a color map.Get the unique data points from sample data, step 2.Plot each color with different labels and color, to place on the legend.Place a legend at the upper right corner within a box.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(3, 3) cmap = cm.YlOrBr unique_data = np.unique(data) i ...

Read More

How to pause a pylab figure until a key is pressed or mouse is clicked? (Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 971 Views

To pause a pylab figure until a key is pressed of mouse is clicked, we can use"button_press_event" key event.StepsSet the figure size and adjust the padding between and around the subplots.Set the "TkAgg" background.Turn the interactive mode ON.Create a new figure or activate an existing figure.Make a variable, pause=False.Whenever "button_press_event", pause the figure.Bind the function to the event.Create data, x and y data points using numpy.Iterate a True loop to change the plot line and color.To display the figure, use show() method.Exampleimport matplotlib from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ...

Read More

How to change the linewidth and markersize separately in a factorplot in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 277 Views

To change the linewidth and markersize separately in a factorplot, we can use the following steps −Set the figure size and adjust the padding between and around the subplots.Load an example dataset from the online repository.Use factorplot() method with scale to change the marker size.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True exercise = sns.load_dataset("exercise") g = sns.factorplot(x="time", y="pulse", hue="kind", data=exercise, ci=95,                   markers=['o', '*', 'd'],                 ...

Read More

How to change the space between bars when drawing multiple barplots in Pandas? (Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 7K+ Views

To change the space between bars when drawing multiple barplots in Pandas within a group, we can use linewidth in plot() method.StepsSet the figure size and adjust the padding between and around the subplots.Make a dictionary with two columns.Create a two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot the dataframe with plot() method, with linewidth that change the space between the bars.Place a legend on the plot.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True d = {'Column 1': [i for i in range(10)],     ...

Read More

How to install Matplotlib without installing Qt using Conda on Windows?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 626 Views

To install Matplotlib package with Conda, run one of the following −conda install -c conda-forge matplotlib-base conda install -c conda-forge/label/testing matplotlib-base conda install -c conda-forge/label/testing/gcc7 matplotlib-base conda install -c conda-forge/label/cf202003 matplotlib-base conda install -c conda-forge/label/matplotlib_rc matplotlib-base conda install -c conda-forge/label/gcc7 matplotlib-base conda install -c conda-forge/label/broken matplotlib-base conda install -c conda-forge/label/matplotlib-base_rc matplotlib-base conda install -c conda-forge/label/rc matplotlib-base conda install -c conda-forge/label/cf201901 matplotlib-base

Read More

How to reuse plots in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 2K+ Views

To reuse plots 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 using figure() method.Plot a line with some input lists.To reuse the plot, update y data and the linewidth of the plotTo display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True line, = plt.plot([1, 3], [3, 4], label="line plot", color='red', lw=0.5) line.set_ydata([3.5]) line.set_linewidth(4) plt.show()Output

Read More

How to modify a Matplotlib legend after it has been created?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 2K+ Views

To modify a Matplotlib legend after it has been created, we can have multiple methods to modify the created legend.Set the figure size and adjust the padding between and around the subplots.Plot a line using plot() method, with two lists and a label.Use legend() method to place a legend over the plot.To modify the matplotlib legend, use set_title() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([1, 3, 4, 5, 2, 1], [3, 4, 1, 3, 0, 1],          label="line plot", color='red', lw=0.5) ...

Read More

Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 18-Jun-2021 624 Views

To plot error bars from a dataframe using Seaborn FacetGrid, we can use following steps −Get a two-dimensional, size-mutable, potentially heterogeneous tabular data.Multi-plot grid for plotting conditional relationships.Apply a plotting function to each facet's subset of the data.To display the figure, use show() method.Exampleimport pandas as pd import seaborn as sns from matplotlib import pyplot as plt df = pd.DataFrame({'col1': [3.0, 7.0, 8.0],                   'col2': [1.0, 4.0, 3.0]}) g = sns.FacetGrid(df, col="col1", hue="col1") g.map(plt.errorbar, "col1", "col2", yerr=0.75, fmt='o') plt.show()Output

Read More
Showing 381–390 of 1,016 articles
« Prev 1 37 38 39 40 41 102 Next »
Advertisements