Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 51 of 102

How to install Matplotlib on Mac 10.7 in virtualenv?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 730 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)

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 1K+ 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

Set a colormap of an image in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 3K+ 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()Output

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 5K+ 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

Read More

How to apply pseudo color schemes to an image plot in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 675 Views

Pseudocolor can be a useful tool for enhancing the contrast and visualizing your data more easily. This is especially useful when making presentations of your data using projectors(because their contrast is typically quite poor).Pseudocolor is only relevant to single-channel, grayscale, luminosity images. We currently have an RGB image. Since R, G, and B are all similar, we can just pick one channel of our data−StepsSet 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 our data.Display data as an image, i.e., on a 2D regular raster.Turn ...

Read More

3D scatterplots in Python Matplotlib with hue colormap and legend

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 3K+ Views

To plot 3D scatter plots in Python with hue colormap and legend, we can take the following steps−Set the figure size and adjust the padding between and around the subplotsCreate x, y and z data points using numpy.Create a new figure or activate an existing figure using figure() method.Get the current axes, creating one if necessary.Get the hue colormap, defining a palette.Plot x, y and z data points using scatter() method.Place a legend on the plot.To display the figure, use show() method.Exampleimport numpy as np import seaborn as sns from matplotlib import pyplot as plt from matplotlib.colors import ListedColormap ...

Read More

How do I fix the deprecation warning that comes with pylab.pause?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 253 Views

To fix the deprecation warning that comes while using a deprecated method, we can use warnings.filterwarnings("ignore") in the code.−Examplefrom matplotlib import pyplot as plt, pylab as pl import warnings plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True warnings.filterwarnings("ignore") pl.pause(0) plt.show()OutputProcess finished with exit code 0

Read More

How to place customized legend symbols on a plot using Matplotlib?

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

To plot customized legend symbols on a plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Inherit HandlerPatch class, override create artists method, add an elliptical patch to the plot, and return the patch handler.Plot a circle on the plot using Circle class.Add a circle patch on the current axis.Use legend() method to place the legend on the plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt, matplotlib.patches as mpatches from matplotlib.legend_handler import HandlerPatch plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True class HandlerEllipse(HandlerPatch):    def create_artists(self, legend, ...

Read More

How to plot a single line in Matplotlib that continuously changes color?

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

To plot a single line that continuously changes color, 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.Create a figure and a set of subplots.Iterate the index in the range of 1 to 100.Plot x and y data points with random color in a loop.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np import random plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 100) y = np.sin(x) fig, ax = plt.subplots() for ...

Read More

Setting the Matplotlib title in bold while using "Times New Roman

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 10K+ Views

To set the Matplotlib title in bold while using "Times New Roman", we can use fontweight="bold".StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Create x and y data points using numpy.Plot x and y data points using scatter() method.Set the title of the plot using fontname="Times New Roman" and fontweight="bold"To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, font_manager as fm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.random.rand(100) y = np.random.rand(100) ax.scatter(x, y, ...

Read More
Showing 501–510 of 1,016 articles
« Prev 1 49 50 51 52 53 102 Next »
Advertisements