Issue
I'm not very knowledgeable about graphs in Python. Is it possible to create a graph generated by my personal algorithm?
I would like to create graphs, but without using the calculation functions of a library. For example, I saw that to create a graph in Scipy
, you must first use its calculation functions that it offers and then the result of the calculation is represented in a graph.
I would like to create a plot of my different My_Customs
, using Matplotlib
's plt.bar
, where some bars are colored red and some are colored green. With label under each bar
How can I represent this in a graph? (I accept any bookstore)
#Green Color
My_Custom_1 = ((1.54 ** 1) * 2.7182818284 ** (-1.54)) / 1 * 100
My_Custom_2 = ((1.54 ** 2) * 2.7182818284 ** (-1.54)) / 2 * 100
My_Custom_3 = ((1.54 ** 3) * 2.7182818284 ** (-1.54)) / 6 * 100
#Red color
My_Custom_0 = ((1.54 ** 0) * 2.7182818284 ** (-1.54)) / 1 * 100
My_Custom_4 = ((1.54 ** 4) * 2.7182818284 ** (-1.54)) / 24 * 100
I have already created a small software that already performs the calculations and returns me the result. I don't want to use a function to calculate Poisson. I would like to directly take the results of the various My_Customs and use them in the graphics.
Solution
"without using library calculation functions" is an anti-goal. You should be at the least using Numpy and not repeating your calculation. The fact that you're using matplotlib
already means that you have numpy installed.
That aside, if you want your bar chart labels to look as they're depicted in your drawing, then
import numpy as np
from matplotlib import pyplot as plt
x = np.arange(5)
d = np.array((1, 1, 2, 6, 24))
my_custom = 1.54**x * 2.7182818284**-1.54 / d * 100
colors = tuple('rgggr')
fig, ax = plt.subplots()
ax.bar(
[f'My_Custom_{i}' for i in x],
my_custom,
color=colors,
)
plt.show()
Answered By - Reinderien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.