Matplotlib Articles

Page 50 of 91

How to plot a remote image from http url using Matplotlib?

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

To plot a remote image from an http URL, we can use io.imread() method to read an URL and take the following steps −Set the figure size and adjust the padding between and around the subplots.Load an image from an http URLUse imshow() method to display data as an image, i.e., on a 2D regular raster.Turn off the axes.To display the figure, use show() method.Examplefrom skimage import io import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True f = "http://matplotlib.sourceforge.net/_static/logo2.png" a = io.imread(f) plt.imshow(a) plt.axis('off') plt.show()Output

Read More

How to add text inside a plot in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 9K+ Views

To add text inside a 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.Place text with some text properties.Plot x and y using plot() method.Turn off the axes.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 100) y = x ** 3 plt.text(0, 100, '$y=x^3$', fontsize=22, bbox=dict(facecolor='red', alpha=0.5)) plt.plot(x, y, c='g') plt.axis('off') plt.show()Output

Read More

How to place X-axis grid over a spectrogram in Python Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 491 Views

To place X-axis grid over a spectrogram in Python, we can use grid() method and take the following steps −Set the figure size and adjust the padding between and around the subplots.Create t, s1, s2, nse, x, NEFT and Fs data points using numpy.Create a new figure or activate an existing figure using subplots() method with nrows=2.Plot t and x data points using plot() method.Lay out a grid in current line style.Set X-axis margins.Plot a spectrogram using specgram() method.Lay out a grid in current line style with dotted linestyle and some other properties.To display the figure, use show() method.Exampleimport matplotlib.pyplot ...

Read More

How to hide axes but keep axis-labels in 3D Plot with Matplotlib?

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

To hide axes but keep axis-labels in 3D plot 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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Create x, y, z, dx, dy and dz data points using numpyUse bar3d() method to plot the 3D bars.To hide the axes, initialize a color tuple, the same as axes color.Set x, y and z axes plane color property same with the color tuple.Set x, y and z axes line color property ...

Read More

How to plot a rectangle on a datetime axis using Matplotlib?

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

To plot a recatangle on a datetime axis using 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 using add_subplot() method.To define a rectangle, find the anchor points using datetime and matplotlib's dates.Add a '~.Patch' to the axes' using add_patch() method.Set major axis locator and formatter.Limit x and y axes scale.To display the figure, use show() method.Examplefrom datetime import datetime, timedelta from matplotlib.patches import Rectangle import matplotlib.pyplot as plt ...

Read More

How to remove scientific notation from a Matplotlib log-log plot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 03-Jun-2021 4K+ Views

To remove scientific notation from a matplotlib log-log plot, we can use ax.xaxis.set_minor_formatter(mticker.ScalarFormatter()) statement.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using scatter() method.Set x and y axes sacle using set_xscale() and set_yscale() methods.To remove scientific notation, use format tick values as a number.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, ticker as mticker plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([1, 7, 6, 4, 0]) y = np.array([6, 2, 3, ...

Read More

How to turn off the upper/right axis tick marks in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 02-Jun-2021 1K+ Views

To turn off the upper or right axis ticks marks in matplotlib, we can make a custom dictionary visible_ticks and turn off the flag.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points using plot() method.Make a dictionary to turn off the axis ticks marks.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(-2, 2, 10) y = np.sin(x) plt.plot(x, y) visible_ticks = { "top": False, ...

Read More

How to work with images in Bokeh (Python)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 02-Jun-2021 808 Views

To work with images in Bokeh, use image_url() method and pass a list of images.StepsConfigure the default output state to generate output saved to a file when :func:'show' is called.Create a new Figure for plotting.Render the images loaded from the given URLs.Immediately display a Bokeh object or application.Examplefrom bokeh.plotting import figure, show, output_file output_file('image.html') p = figure(x_range=(0, 1), y_range=(0, 1)) p.image_url(url=['bird.jpg'], x=0, y=1, w=0.8, h=0.6) show(p)Output

Read More

How to show legend elements horizontally in Matplotlib?

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

To show legend elements horizontally, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Using plot() method, plot lines with the labels line1, line2 and line3.Place a legend on the figure using legend() method, with number of labels for ncol value in the argument.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 line1, = plt.plot([1, 2, 3], label="line1") line2, = plt.plot([3, 2, 1], label="line2") line3, = plt.plot([2, 3, 1], label="line3") plt.legend(ncol=3, loc="upper right") plt.show()Output

Read More

How to change the color of a single bar if a condition is true (Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 02-Jun-2021 6K+ Views

To change the color of a single bar if a condition is true, we can make a set of values and a list of colors with red until the value is 2; else add yellow color in the list.StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable width of a bar.Make two lists of values and colors.Use bar() method to plot bars.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 data = np.arange(5) width = 0.5 vals = [1, 2, 1, 5, ...

Read More
Showing 491–500 of 902 articles
« Prev 1 48 49 50 51 52 91 Next »
Advertisements