Rishikesh Kumar Rishi has Published 1162 Articles

Show Matplotlib plots (and other GUI) in Ubuntu

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:28:38

1K+ Views

Use the plot method of matplotlib and set the legend with different sets of colors.StepsSet the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Plot the lines using plt.plot() method with [9, 5], [2, 5] and [4, 7, 8] array.Initialize two variables; location = 0 for the best ... Read More

How to save a figure remotely with pylab in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:27:59

448 Views

Using the savefig method of the pyplot package, we can save the figure remotely by specifying the location of the figure.StepsTo use a different backend, set it using matplotlib.use('Agg') method.Plot the lines using plot() method.Using savefig() method, we can save the image remotely, just putting the directory.To show the figure, ... Read More

How can I cycle through line styles in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:27:19

273 Views

To plot multiple lines in a diagram, we can use the cycler that could help to set a new color from the given list of colors. (Here, ‘r’ => ‘red’, ‘g’ => ‘green’, ‘y’ => ‘yellow’, ‘b’ => ‘blue’).StepsUse a cycler to set the color for the group of lines. ... Read More

Putting a newline in Matplotlib label with TeX in Python

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:25:47

3K+ Views

The following program code shows how you can plot a newline in matplotlib label with Tex.StepsSetup X-axis and Y-axis labels for the diagram with to plot a newline in the labels.Set the current .rcParams for axes facecolor; the group is axed.Use a cycler to set the color for the ... Read More

Drawing average line in histogram in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:18:07

2K+ Views

We can plot some expressions using the hist method. After that, we will plot the average graph for the expression using the plot method and bins that are returned while creating the hist.StepsGet the data for x using some equations, set num_bins = 50.Create fig and ax variables using subplots ... Read More

How to prevent numbers being changed to exponential form in Python Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:17:18

767 Views

Using style='plain' in the ticklabel_format() method, we can restrict the value being changed into exponential form.StepsPass two lists to draw a line using plot() method.Use ticklabel_format() method with style='plain'. If a parameter is not set, the corresponding property of the formatter is left unchanged. Style='plain' turns off scientific notation.To show ... Read More

Using Colormaps to set the color of line in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:16:54

1K+ Views

First, we can create a list of colors, and then, we can use the colors while plotting a line in a loop.StepsReturn evenly spaced numbers over a specified interval, store in x.Update x for four lines and get another variable for evenly_spaced_interval.Make a list of colors.Iterate color and set color ... Read More

Generating a movie from Python without saving individual frames to files

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:14:06

301 Views

Using the FuncAnimation method, we can create a film. We will create a user-defined method, update, to keep on changing the position of particles and at the end, the method would return the scatter instance.StepsGet the particles initial position, velocity, force, and size.Create a new figure, or activate an existing ... Read More

How to turn on minor ticks only on the y-axis Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:02:26

2K+ Views

First, we can create fig, ax using subplots() and then, we can plot the lines. After that, using ax.yaxis.set_minor_locator(tck.AutoMinorLocator()), we can turn on the minor ticks.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Plot the line using two lists.Set the locator of the minor ... Read More

How to zoom subplots together in Matplotlib/Pyplot?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:01:02

2K+ Views

We can use the attribute sharex = "ax1", and then, use the subplot method to zoom the subplots together.StepsAdd a subplot to the current figure with (nrow = 1, ncols = 2, index = 1).Add line on the current subplot with (nrow = 1, ncols = 2, index = 1).Add ... Read More

Advertisements