Photo
Hi I have written this code to display pivot, but pivot lines (red,orange,yellow) on the current bar seem weird like the photo above, and I want to make it straight or continued just as the pivot lines on the previous bars. Their values just suddenly change from the previous to the current bar. My intention is displaying pivots from the yesterday's data throughout the bars today. Could anyone please help me to fix this, please? The version is #5.
pma = request.security(syminfo.tickerid, 'D', hlc3[1])
diff = request.security(syminfo.tickerid, 'D', hl2[1])
pr = pma-diff
ph = pma+pr
pl = pma-pr
plot(pma, linewidth=2, color=color.new(color.orange, 0))
plot(ph, linewidth=2, color=color.new(color.red,0))
plot(pl, linewidth=2, color=color.new(color.yellow,0))
Use the lookahead parameter
pma = request.security(syminfo.tickerid, 'D', hlc3[1],barmerge.gaps_off, barmerge.lookahead_on)
diff = request.security(syminfo.tickerid, 'D', hl2[1], barmerge.gaps_off, barmerge.lookahead_on)
Source: https://www.tradingview.com/pine-script-reference/v5/#fun_request{dot}security
Related
I am doing a Dash Project for a company, and I am stuck in plotting a Multiple Trace Radar Chart in plotly.
My current progress looks like this:-
What I want is to find a way to get Data Science and Profile Building theta category close to each other, so that the February-2020 trace is not a line but a fill, similar to how it shows in March-2020 trace. Till now I couldn't find any solution to it.
The data I used to plot the chart is as follows:-
Code for the chart:-
fig = go.Figure()
months = np.unique(df['month'].values).tolist()
months.reverse()
for i in months:
temp = df.query('month=="{}"'.format(str(i)))
q = temp['module'].values.tolist()
r = temp['rating'].values.tolist()
q.append(q[0])
r.append(r[0])
fig.add_trace(go.Scatterpolar(theta=q,r=r,fill='toself',name=str(i),hoveron='points'))
fig.update_layout(
polar=dict(
radialaxis=dict(
visible=True,
range=[0, 10]
)),
showlegend=True
)
fig.show()
Any help would be greatly appreciated! Thanks in Advance
Newbie here, first question.
I have several data files, that I want to open, get the relevant data (x and y) and plot on the same plot.
I know how to do it if I type out a plot statement for each of them, but what I would want to create is a single function or script that takes the filenames as input, extracts the data (this part depends on the type of file, but I think I know how to do it) and then creates one single plot with the different datasets. It should be pretty basic, but all my attempts return a plot for each file.
I think that my problem is that I have not understood how the whole ax, fig, gca, plot loop works, as I have been learning mostly by adapting things and doing.
So far I have created a for loop that opens each file, gets the data and stores it in a dataframe (a dataframe per file) then uses a plt.plot to plot, and then out of the loop, I have a plt.gca() that in my intentions would get things together to then modify the plot, add stuff to it and save it. I have also tried changing the position of the gca and using ax and fig, playing around with a few tutorials, but never with satisfying results.
I get different kinds of errors, depending on the different iterations of the script, here is one of my attempts. If there's an electrochemist among you they might recognize the datatype :) but the datatype should not be important.
**EDIT: I modified the script, as it had a couple of errors, the current versions returns an empty plot.
**
the current version returns an empty plot, the dataframe is created properly, from what I can see
files = ['file1.i2b', 'file2.i2b']
colors = []
fig_name = ''
file_type = 'i2b'
norm = []
if len(colors) != len(files):
l = len(files)
col_list = ['b', 'g', 'r', 'c', 'm', 'y', 'k']
color_list = col_list[0:l]
if len(norm)!= len(files):
norm = [1]*len(files)
if file_type == 'i2b':
for filename, norm_factor, col in zip (files, norm, color_list):
flnm1 = os.path.splitext(filename)[0]
data_xrd = pd.read_csv(filename, sep=(' '), decimal = '.', skiprows =10,
header= None, names =['Freq','Real_part', 'Imm_part'])
data_xrd['norm_Imm_part'] = (0-data_xrd['Imm_part'])*norm_factor
data_xrd['norm_Re_part'] = data_xrd['Real_part']*norm_factor
plt.plot(x=data_xrd['norm_Re_part'], y=data_xrd['norm_Imm_part'],
legend=flnm1, style='-', color = col)
#plt.show
plt.gca()
#plt.axhline(y=0, color='k', linestyle='--')
#plt.set_xlabel('Z_real [Ohm]')
#plt.set_ylabel('Z_imm [Ohm]')
#plt.set_aspect('equal')
plt.savefig(fig_name + '.png')
Now, it might be better to split the data extraction to a different function, so that the plotting function is more flexible and can be paired with different kinds of data input, but at the moment I'd just like to understand how to use plot multiple files on a single plot simply by using a list of their names as input, in order to facilitate the grouping and plotting of a lot of datafiles.
Thanks for the help and please let me know how to improve my question!
I'm working on project where I have to create plots for multiple states. I know I can use subplots but they are not producing visually pleasing results so I would rather keep them printed one after the other.
At the end of the for loop, whenever I need to find info I have to scroll around trying to find certain states. Is it possible to have the locations printed at the top so I can quickly jump to the graph?
I have provided my code as it is now.
the08legend = [] '$'
print(the08legend)'$'
for state in state_df['State'].unique():'$'
the08legend.append(state)
plt.figure(figsize = (8,8))
my_range =range(1,len(state_df[state_df['State']==state].index)+1)
st_df = state_df[state_df['State'] == state]
st_df = st_df.sort_values('rep08vot_perc')
plt.axvline(x=50, c='green', alpha = 0.2)
plt.hlines(y=my_range, xmin=st_df['rep08vot_perc'], xmax=st_df['dem08vot_perc'], color='ghostwhite', alpha=1)
plt.scatter(y = my_range, x = st_df['rep08vot_perc'], c = 'red', label='Republican vote share')
plt.scatter(y = my_range, x = st_df['dem08vot_perc'], c = 'blue', label = 'Democrat vote share')
plt.xlim(0,100)
plt.title(f'The vote shares in {state} 2008 election')
plt.ylabel(f'The county in {state} where vote was counted')
plt.xlabel('Percentage share of votes')
plt.legend(loc = 1)
plt.show()
I know what I did is obviously not going to print the resulting list, however, is it possible to make that happen?
row1a = Canvas(firstFrame,width=54,height=54,bg="gray")
row1a.pack(side=LEFT)
row1b = Canvas(firstFrame,width=54,height=54,bg="gray40")
row1b.pack(side=LEFT)
row1c = Canvas(firstFrame,width=54,height=54,bg="gray")
row1c.pack(side=LEFT)
row1d = Canvas(firstFrame,width=54,height=54,bg="gray40")
row1d.pack(side=LEFT)
row1e = Canvas(firstFrame,width=54,height=54,bg="gray")
row1e.pack(side=LEFT)
row1f = Canvas(firstFrame,width=54,height=54,bg="gray40")
row1f.pack(side=LEFT)
row1g = Canvas(firstFrame,width=54,height=54,bg="gray")
row1g.pack(side=LEFT)
row = 1
column = b
Is there a way i can update the "row1b" canvas' colour using something like canvas.config(bg="blue").
There are a lot more of these canvases so I cant really use row1b.config(bg="blue") for each canvas.
Thank you!
Like with any widget, you can change its options after it's been created.
Since you are creating many canvases, the best solution is to store them in a list or dictionary. Since you seem to want to reference them with numbers and letters, a dictionary might be the best solution.
For example, to create the canvas objects in a loop you could do something like this:
canvases = {}
row = 1
for column in ('a', 'b', 'c', 'd', 'e', 'f', 'g'):
index = (row, column)
canvases[index] = Canvas(...)
Later, you can change the color of any single canvas via the canvases dictionary and the configure command:
canvases[(1,'c')].configure(background="blue")
I have two environments, A and B, in a CROSS TABLE. Each environment has stores with the amount of units next to them. Additionally, there is a column that shows the percentage of total units for each store in each environment.
The code for percentage of total is as follows:
Sum([UNITS]) THEN [Value] / Sum([Value]) OVER (All([Axis.Rows])) as [% Units]
Let's say store 1 has a different percentage of total for each environment. I want to create a separate custom expression that shows the difference between these two percentages.
Right now, I have a variation of this that is not desirable. It simply shows the percent change in units for store 1, rather than the change in the percentage of total. This code looks like:
(Sum([UNITS]) - Sum([UNITS]) OVER (PreviousPeriod([Axis.Columns]))) / Sum([UNITS]) OVER (PreviousPeriod([Axis.Columns])) as [Unit Difference]
I have tried unsuccessfully to embed the first piece of code within the second piece. Any help will be greatly appreciated!
I believe what you're looking for is something along the lines of
SUM(If([Environment] = 'A', [Units], 0))/(SUM(If([Environment] = 'A', [Units], 0)) OVER (Parent([Axis.Rows])) - SUM(If([Environment] = 'B', [Units], 0))/(SUM(If([Environment] = 'B', [Units], 0)) OVER (Parent([Axis.Rows])) as [% Difference]
This would require removing the A/B differentiation from the Horizontal access and replacing it with (Column Names) and making two different columns of custom expressions, composed of
SUM(If([Environment] = 'A', [Units], 0))/(SUM(If([Environment] = 'A', [Units], 0)) OVER (Parent([Axis.Rows])) as [A %]
and
SUM(If([Environment] = 'B', [Units], 0))/(SUM(If([Environment] = 'B', [Units], 0)) OVER (Parent([Axis.Rows])) as [B%]
If this is not what you are looking for, I suggest you clarify with an example with example numbers showing what you want the output to look like.