Rishikesh Kumar Rishi has Published 1162 Articles

How to improve the label placement for Matplotlib scatter chart?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:49:25

1K+ Views

To imporove the label placement for matplotlib scatter chart, we can first plot the scatter points and annotate those points with labels.StepsCreate points for x and y using numpy.Create labels using xpoints.Use scatter() method to scatter points.Iterate the labels, xpoints and ypoints and annotate the plot with label, x and y with different properties.To ... Read More

How to plot bar graphs with same X coordinates side by side in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:48:07

1K+ Views

To plot bar graphs with same X coordinates (G1, G2, G3, G4 and G5), side by side in matplotlib, we can take the following steps −Create the following lists – labels, men_means and women_means with different data elements.Return evenly spaced values within a given interval, using numpy.arrange() method.Set the width variable, ... Read More

Plot scatter points using plot method in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:47:24

487 Views

To plot scatter points using plot method in matplotlib, we can take the following steps−Create random data points (x1 and x2) using numpy.Plot x1 data points using plot() method with marker size 20 and green color.Plot x2 data points using plot() method with marker size 10 and red color.Exampleimport numpy ... Read More

Changing the formatting of a datetime axis in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:47:02

6K+ Views

To change the formatting of a datetime axis in matplotlib, we can take the following steps−Create a dataframe df using pandas DataFrame with time and speed as keysCreate a figure and a set of subplots using subplots() method.Plot the dataframe using plot method, with df's (Step 1) time and speed.To ... Read More

Save figure as file from iPython notebook using Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:46:34

4K+ Views

To save a figure as a file from iPython, we can take the following steps−Create a new figure or activate an existing figure.Add an axes to the figure using add_axes() method.Plot the given list.Save the plot using savefig() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

How to plot 2D math vectors with Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:46:09

3K+ Views

To plot 2D math vectors with matplotlib, we can take the following steps−Create vector cordinates using numpy array.Get x, y, u and v data points.Create a new figure or activate an existing figure using figure method.Get the current axis using gca() method.Set x an y limits of the axes.To redraw ... Read More

Wrapping long Y labels in Matplotlib tight layout using setp

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:45:34

868 Views

To wrap long Y label in matplotlib tight layput using setp, we can take the following steps−Create a list of a long strings.Create a tuple of 3 values.Create a figure and add a set of subplots.Limit the Y-axis ticks using ylim() method.Make a horizontal bar plot, using barh() method.Use yticks() ... Read More

How to create a standard colorbar for a series of plots in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:44:46

381 Views

To create a standard colorbar for a series of plots, we can take the following steps −Create random data using numpy.Create a figure and a set of subplot using subplots() method, where nrows=1 and ncols=1.Display data as an image.Add an axes to the figure, for colorbar.Create a colorbar where mappable ... Read More

How to get a list of all the fonts currently available for Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:37:23

3K+ Views

To get a list of all the fonts currently available for matplotlib, we can use the font_manager.findSystemFonts() method.StepsPrint a statement.Use font_manager.findSystemFonts() method to get a list of fonts availabe.Examplefrom matplotlib import font_manager print("List of all fonts currently available in the matplotlib:") print(*font_manager.findSystemFonts(fontpaths=None, fontext='ttf'), sep="")Output/usr/share/fonts/truetype/Nakula/nakula.ttf /usr/share/fonts/truetype/ubuntu/Ubuntu-L.ttf /usr/share/fonts/truetype/tlwg/Loma-BoldOblique.ttf ................................................................. ............................................................................ ................................................................................. ........ ... Read More

Top label for Matplotlib colorbars

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:36:51

7K+ Views

To place a top label for colorbars, we can use colorbar's axis to set the title.StepsCreate random data using numpy.Use imshow() method to represent data into an image, with colormap "PuBuGn" and interpolation= "nearest".Create a colorbar for a scalar mappable instance, imSet the title on the ax (of colorbar) using ... Read More

Advertisements