Rishikesh Kumar Rishi has Published 1156 Articles

How to create a stacked bar chart for my DataFrame using Seaborn in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 08:00:15

1K+ Views

To create a stacked bar chart, we can use Seaborn's barplot() method, i.e., show point estimates and confidence intervals with bars.Create df using Pandas Data Frame.Using barplot() method, create bar_plot1 and bar_plot2 with color as red and green, and label as count and select.To enable legend, use legend() method, at the upper-right location.To display ... Read More

Plot a histogram with colors taken from colormap in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:59:54

2K+ Views

To plot a histogram with colors taken from colormap, we can use the setp() method.StepsCreate data points using numpy.Plot data (Step 1) using hist() method, with bins=25, rwidth=.75, ...etc.Returned values n, bins and patches can help to find col.Get a colormap instance for name "RdYlBu".Zip the col and patches.Now, using setp() method, set ... Read More

Matplotlib figure to image as a numpy array

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:59:03

3K+ Views

We can use the following steps to convert a figure into a numpy array −Read a figure from a directory; convert it into numpy array.Use imshow() method to display the image.Use show() method to display it.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True im = ... Read More

Auto adjust font size in Seaborn heatmap using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:58:28

2K+ Views

To adjust font size in Seaborn, we can take followig steps−Create a dictionary with some mathematical expressionsCreate a dataframe using Pandas data frame.Create a heatmap using heatmap() method.To adjust the font size in Seaborn heatmap, change the fontsize value.To display the figure, use show() method.Exampleimport numpy as np import seaborn ... Read More

Drawing multiple figures in parallel in Python with Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:57:56

994 Views

To draw multiple figures in parallel in Python with matplolib, we can take the following steps−Create random data using numpy.Add a subplot to the current figure, nrows=1, ncols=4 and at index=1.Display data as an image, i.e., on a 2D regular raster, using imshow() method with cmap="Blues_r".Add a subplot to the ... Read More

How do I show logarithmically spaced grid lines at all ticks on a log-log plot using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:57:03

3K+ Views

To show logarithmically spaced grid lines at all ticks on a log-log plot using matplotlib, we can take the following steps−Create data points for x and y using numpy.Using loglog method, make a plot with log scaling on both the X and Y axis.Use grid() method, lay out a grid ... Read More

Set Max value for color bar on Seaborn heatmap using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:52:19

645 Views

To set a value for color bar on Seaborn heatmap, we can take following Steps−Create random data using numpy.Use heatmap() method to plot rectangular data as a color-encoded matrix.To display the figure, use show() method.Exampleimport numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = ... Read More

Putting arrowheads on vectors in Matplotlib's 3D plot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:47:53

2K+ Views

To draw arrow heads vectors in 3D matplotlb's plot, we can take the following steps −Create a 2D array, where x, y, z, u, v and w are the coordinates of the arrow locations and direction components of arrow vectors.Using figure() method, create a new figure or activate an existing figure.Add an '~.axes.Axes' to ... Read More

Remove the X-axis ticks while keeping the grids (Matplotlib)

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:46:18

3K+ Views

To remove the X-ticks while keeping the grids, we can take the following steps−Use gca() method to get the current axes, creating one if necessary.Plot the x and np.sin(x) using plot() method with linewidth=5, label y=sin(x).Remove yticks and xticks by passing empty array in the argument of set_xticklabels and set_yticklabels ... Read More

Plotting a transparent histogram with non-transparent edge in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 07-May-2021 07:45:49

1K+ Views

To plot a transparent histogram with non-transparent edge, we can take the following steps−Create a set of random data points (y).Initialize the number of bins to be drawn.To plot the histogram, we can use hist() method with edge color and facecolor tuplesTo display the figure, use show() method.Exampleimport numpy as ... Read More

Advertisements