Rishikesh Kumar Rishi has Published 1156 Articles

How can I get the output of a Matplotlib plot as an SVG?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

17K+ Views

Just using the savefig method of the pyplot package and mentioning the file format, we can save the output as a SVG format.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Create xpoints and ypoints using np.array(0, 5).Plot lines using xpoints and ypoints.Set the X-axis ... Read More

Change figure size and figure format in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:43:42

1K+ Views

Using the figsize attribute of figure(), we can change the figure size. To change the format of a figure, we can use the savefig method.StepsStore the figure size in the variable.Create a new figure, or activate an existing figure, with given figure size.Plot the line using x.Set the image title ... Read More

How to print the Y-axis label horizontally in a Matplotlib/Pylab chart?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

3K+ Views

Just by using plt.ylabel(rotation='horizontal'), we can align a label according to our requirement.StepsPlot the lines using [0, 5] and [0, 5] lists.Set the y-label for Y-axis, using ylabel method by passing rotation='horizontal'.Set the x-label for X-axis, using xlabel method.To show the plot, use plt.show() method.Examplefrom matplotlib import pyplot as plt ... Read More

Displaying rotatable 3D plots in IPython or Jupyter Notebook

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:36:34

3K+ Views

By creating a 3D projection on the axis and iterating that axis for different angles using view_init(), we can rotate the output diagram.StepsCreate a new figure, or activate an existing figure.Add an `~.axes.Axes` to the figure as part of a subplot arrangement with nrow = 1, ncols = 1, index ... Read More

Barchart with vertical labels in Python/Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 08:32:55

9K+ Views

First, we can create bars using plt.bar and using xticks. Then, we can align the labels by setting the “vertical” or “horizontal” attributes in the “rotation” key.StepsMake lists, bars_heights, and bars_label, with numbers.Make a bar plot using bar() method, with bars_heights and length of bars_label.Get or set the current tick ... Read More

Show Matplotlib plots (and other GUI) in Ubuntu

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

2K+ 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

546 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

416 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

4K+ 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

Advertisements