Pass RGB Color Values to Matplotlib Eventplot in Python

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:07:56

2K+ Views

To pass RGB color values to Python's Matplotlib eventplot, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a 1D array, pos, to define the positions of one sequence of eventsMake a list of color tuple r, g, b.Plot identical parallel lines at the given positions.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True pos = 10 * np.random.random(100) colors = [(0.75, 0.50, 0.25)] plt.eventplot(pos, orientation='horizontal',                linelengths=0.75, color=colors) ... Read More

Put Gap Between Y-Axis and First Bar in Vertical Barchart in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:07:38

2K+ Views

To put gap between Y-axis and the first bar in vertical barchart, we can reduce the X-axis scale.StepsSet the figure size and adjust the padding between and around the subplots.Create lists x_val, x_names andvaldata points. Also, initialize width and interval variables.Make a bar plot using bar() method.Get or set the current tick locations and labels of the X-axis.Get or set the current tick locations and labels of the Y-axis.Get or set the x limits of the current axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x_val = ... Read More

Embed Fonts in PDFs Produced by Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:07:08

1K+ Views

To embed fonts in PDFs produced by Matplotlib, we can use rc.Params['pdf.fonttype']=42.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure, using figure() method.Create x and y data points using numpy.Plot x and y data points using scatter() method.Set the title of the plot.Save the figure in pdf format.Exampleimport numpy as np from matplotlib import pyplot as plt, font_manager as fm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rcParams['pdf.fonttype'] = 42 fig, ax = plt.subplots() x = np.random.rand(100) y = np.random.rand(100) ax.scatter(x, y, c=y, marker="v") ... Read More

Animate the Colorbar in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 09:08:33

2K+ Views

To animate the colorbar in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Instantiate Divider based on the pre-existing axes, i.e., ax object and return a new axis locator for the specified cell.Create an axes at the given *position* with the same height (or width) of the main axes.Create random data using numpy.Use imshow() method to plot random data.Set the title of the plot.Instantiate the list of colormaps.To animate the ... Read More

Matplotlib Animation Not Working in IPython Notebook

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 09:05:40

2K+ Views

To animate a plot in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a random data of shape 10X10 dimension.Create a figure and a set of subplots, using subplots() method.Makes an animation by repeatedly calling a function *func*, using FuncAnimation() class.To update the contour value in a function, we can define a method animate that can be used in FuncAnimation() class.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = ... Read More

Draw a Turing Machine to Find 2's Complement of a Binary Number

Bhanu Priya
Updated on 15-Jun-2021 15:33:34

9K+ Views

2’s complement of binary numbers can be done by using two approaches.Adding 1’s complement+1Traverse bits from left to right, find the 1st 1 bit then reverse all the bits after the 1 bit.ExampleLet the input be 1110010Thus, after performing 2’s complement, the output will be as follows −Output − 0001110Coming to the Turing machine to find 2’s complement, If input is as follows −B010000100The output is as follows −B101111100ExplanationStep 1 − Here, we need to start from the rightmost ends.Step 2 − We will move the R/W head all the way to the right, skipping all the 0s and 1s.Step ... Read More

Draw a Turing Machine to Find 1's Complement of a Binary Number

Bhanu Priya
Updated on 15-Jun-2021 15:24:58

5K+ Views

1’s complement means transforming the 0 bit to 1 and the 1 bit to 0.Let the input be −B00101110BThe output is as follows −B11010001BConceptThe concept is explained below −Step 1 − Start scanning the input from left to right.Step 2 − If the R/W is at 1, then make it 0 and move right.Step 3 − If the R/W is at 0, then make it 1 and move right.Step 4 − Repeat the steps given above and we will reach B (blank).Step 5 − Then move the R/W head all the way to the left without changing anything until it ... Read More

Construct a TM for the Language L = { ww | w ∈ {0, 1} }

Bhanu Priya
Updated on 15-Jun-2021 15:12:46

2K+ Views

ProblemThe language L = {ww | w ε {0, 1}} having the string of 0’s and 1’s which is followed by itselfL={00, 11, 1100, 0011, …..}SolutionThe logic for solving the problem is as follows −Find the midpoint of the string.Then match the symbols.ExplanationStep 1 − First, we need to find the midpoint of the string.Step 2 − We will make the first 0 to X or 1 to Y and then move R/W head to the right until the last character is found.Step 3 − Then make this 0 to X or 1 to Y.Step 4 − Now, we will ... Read More

Construct PDA for Accepting L = { a^n b^{2n} | n ≥ 1 } ∪ { a^n b^n | n ≥ 1 }

Bhanu Priya
Updated on 15-Jun-2021 15:07:47

2K+ Views

A push down automata (PDA) can be formally described as seven tuples(Q, Σ, S, δ, q0, I, F)Where, Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of accepting statesProblemConstruct PDA for L = {anb(2n) | n>=1} ∪ {anbn | n>=1}SolutionLetL = {anb(2n) | n>=1}{anbn | n>=1}Construct PDA for L= L1 U L2So, the strings which are generated by the given language L1 are as follows−L1={abb, aabbbb, aaabbbbbb, ….} andL2= {ab, aabb, aaabbb, ….}L= L1 ... Read More

Construct a DPDA for anbn^2n-n-1 in TOC

Bhanu Priya
Updated on 15-Jun-2021 15:05:23

26K+ Views

A deterministic finite automata (DFA) can remember a finite amount of information but A push down automata (PDA) can remember an infinite amount of information.Basically a PDA is as follows −“Finite state machine+ a stack”PDA has three components, which is as follows −An Input tapeA control unitA Stack with infinite sizeA PDA can be formally described as seven tuples (Q, Σ, S, δ, q0, I, F)Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of ... Read More

Advertisements