Rishikesh Kumar Rishi has Published 1162 Articles

Golang program to define a binary tree

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 17-Mar-2021 10:52:12

553 Views

Example − In the given tree, the root node is 1, the root of its left sub tree is 2, and the root of its right sub tree is 3, ... so on.Preorder Tree Traversal Output: 1, 2, 4, 5, 3, 6, 7.Approach to solve this problemStep 1 − First, ... Read More

Text box with line wrapping in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

1K+ Views

Matplotlib can wrap text automatically, but if it's too long, the text will be displayed slightly outside of the boundaries of the axis anyways.StepsCreate a new figure, or activate an existing figure, using figure().Set the axis properties using plt.axis() method.Make a variable input_text to store the string.Add text to figure, ... Read More

Plot mean and standard deviation in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

9K+ Views

First, we can calculate the mean and standard deviation of the input data using Pandas dataframe.Then, we could plot the data using Matplotlib.StepsCreate a list and store it in data.Using Pandas, create a data frame with data (step 1), mean, std.Plot using a dataframe.To show the figure, use plt.show() method.Exampleimport ... Read More

How to overplot a line on a scatter plot in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

11K+ Views

First, we can create a scatter for different data points using the scatter method, and then, we can plot the lines using the plot method.StepsCreate a new figure, or activate an existing figure with figure size(4, 3), using figure() method.Add an axis to the current figure and make it the ... Read More

How do I format the axis number format to thousands with a comma in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

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

4K+ Views

First, we can make two lists of x and y, where the values will be more than 1000. Then, we can use the ax.yaxis.set_major_formatter method where can pass StrMethodFormatter('{x:, }') method with {x:, } formatter that helps to separate out the 1000 figures from the given set of numbers.StepsMake two ... Read More

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

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

761 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

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

Advertisements