Plot excel bar chart from Matlab - excel

How do I plot excel bar chart from Matlab?
I'm able to plot line chart.
e = actxserver('excel.application');
eWs = e.Workbooks;
eW = eWs.Add;
eS = eW.ActiveSheet;
e.Visible = 1;
x=(0:2:100)';y=sin(x);
eS.Range('A1:B50').Value = [x y];
eCO = eS.ChartObjects.Add(100, 30, 400, 250);
eC = eCO.Chart;
eC.SeriesCollection.NewSeries;
eC.SeriesCollection(1).Value = eS.Range('B1:B50');
eC.SeriesCollection(1).XValue = eS.Range('A1:A50');
eCO.Chart.ChartType = 1;
eCO.Chart.ChartType = 65;
eCO.Chart.HasTitle = true;
eCO.Chart.ChartTitle.Text = 'This is the title text'; % view it again
eW.Close;e.Quit;delete(e);

Ok, I figured it out just after posting it.
We can get this by changing
eCO.Chart.ChartType = 65; to eCO.Chart.ChartType = 57;
e = actxserver('excel.application');
eWs = e.Workbooks;
eW = eWs.Add;
eS = eW.ActiveSheet;
e.Visible = 1;
x=(0:2:100)';y=sin(x);
eS.Range('A1:B50').Value = [x y];
eCO = eS.ChartObjects.Add(100, 30, 400, 250);
eC = eCO.Chart;
eC.SeriesCollection.NewSeries;
eC.SeriesCollection(1).Value = eS.Range('B1:B50');
eC.SeriesCollection(1).XValue = eS.Range('A1:A50');
eCO.Chart.ChartType = 1;
eCO.Chart.ChartType = 57;
eCO.Chart.HasTitle = true;
eCO.Chart.ChartTitle.Text = 'This is the title text'; % view it again
eW.Close;e.Quit;delete(e);
For further reference to other charts check this http://it.toolbox.com/wiki/index.php/EXCEL_Chart_Type_Enumeration

Related

How to change color of mark on topoplot interactively?

I want to create interactive line- and topoplot depending on menu. I figured out how to make red the line chosen in menu, but it doesn't work for topoplot marks (black circles inside topoplot). I can change it manually (cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)), but how to do that interactively?
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1:3, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")
N = 1:length(pos) #1:4
hidespines!(ax, :t, :r)
GLMakie.xlims!(-0.3, 1.2)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
times = range(-0.3, length=size(dat_e,2), step=1 ./ 128)
lines = Dict()
for i in N
mean_trial = mean(dat_e[i,:,:],dims=2)[:,1]
line = lines!(times, mean_trial, color = "black")
lines[i] = line
end
hidedecorations!(ax, label = false, ticks = false, ticklabels = false)
topo_axis = Axis(f[2, 2], width = 178, height = 178, aspect = DataAspect())
Makie.xlims!(low = -0.2, high = 1.2)
Makie.ylims!(low = -0.2, high = 1.2)
topoMatrix = eegHeadMatrix(pos[N], (0.5, 0.5), 0.5)
cmap = Observable(collect(ColorScheme(range(colorant"black", colorant"black", length=30))))
#cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)
topo = eeg_topoplot!(topo_axis, N, # averaging all trial of 30 participants on Xth msec
raw.ch_names[1:30];
positions=pos, # produced automatically from ch_names
interpolation=NullInterpolator(),
enlarge=1,
#colorrange = (0, 1), # add the 0 for the white-first color
colormap = cmap[],
label_text=false)
hidedecorations!(current_axis())
hidespines!(current_axis())
num_prev = 0
menu = Menu(f[3, 2], options = raw.ch_names[1:30], default = nothing)#, default = "second")
on(menu.selection) do selected
if selected != nothing
num = findall(x->x==menu.selection[], raw.ch_names[1:30])[]
if num_prev != 0
lines[num_prev].color = "black"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
end
lines[num].color = "red"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
num_prev = num
end
end
notify(menu.selection)
#print(cmap[])
f
We solved this by putting this string at the end of the menu.selection section:
notify(lines)
It works, because lines() automatically creates Observable.

Why am i not getting any visualisation Vpython?

I am trying to simulate some planets and their moons around the sun but not getting scene opened up.`from vpython import*
def open_scene(breedte, hoogte):
global open_venster
c = canvas(width=breedte, height=hoogte, background=color.black)
c.center = vector(0,0,0)
c.range = breedte
c.autozoom = True
c.autoscale = False
c.userzoom = True
c.userspin = False
c.userpan = False
return c
open_scene(400, 400)
def solarsystem(n, dt):
He = planets_from_file("planeten.txt")
planets = []
sun = sphere(pos = vector(0,0,0), radius = He[0].straal_v_hemellichaam, color = kleuromzetting(He[0].kleur))
earth = sphere(pos = vector(-He[3].straal_vd_baan, 0, 0), radius= He[3].straal_v_hemellichaam*50, texture= textures.earth)
moon = sphere(pos = vector(-He[4].straal_vd_baan,0,0), radius = He[4].straal_v_hemellichaam, color = kleuromzetting(He[4].kleur))
mercurius = sphere(pos = vector(-He[1].straal_vd_baan,0,0), radius = He[1].straal_v_hemellichaam, color = kleuromzetting(He[1].kleur))
venus = sphere(pos = vector(-He[2].straal_vd_baan,0,0), radius = He[2].straal_v_hemellichaam, color = kleuromzetting(He[2].kleur))
mars = sphere(pos = vector(-He[5].straal_vd_baan,0,0), radius = He[5].straal_v_hemellichaam, color = kleuromzetting(He[5].kleur))
phobos = sphere(pos = vector(-He[6].straal_vd_baan-He[5].straal_vd_baan,0,0), radius = He[6].straal_v_hemellichaam, color = kleuromzetting(He[6].kleur))
deimos = sphere(pos = vector(-He[7].straal_vd_baan-He[5].straal_vd_baan,0,0), radius = He[7].straal_v_hemellichaam, color = kleuromzetting(He[7].kleur))
jupiter = sphere(pos = vector(-He[8].straal_vd_baan,0,0), radius = He[8].straal_v_hemellichaam, color = kleuromzetting(He[8].kleur))
io = sphere(pos = vector(-He[9].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[9].straal_v_hemellichaam, color = kleuromzetting(He[9].kleur))
europa = sphere(pos = vector(-He[10].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[10].straal_v_hemellichaam, color = kleuromzetting(He[10].kleur))
ganymede = sphere(pos = vector(-He[11].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[11].straal_v_hemellichaam, color = kleuromzetting(He[11].kleur))
callisto = sphere(pos = vector(-He[12].straal_vd_baan-He[8].straal_vd_baan,0,0), radius = He[12].straal_v_hemellichaam, color = kleuromzetting(He[12].kleur))
sun.velocity = vector(0, 0, 0)
earth.velocity = He[3].snelheid
moon.velocity = He[4].snelheid
mercury.velocity = He[1].snelheid
venus.velocity = He[2].snelheid
mars.velocity =He[5].snelheid
phobos.velocity = He[6].snelheid
deimos.velocity = He[7].snelheid
jupiter.velocity = He[8].snelheid
io.velocity = He[9].snelheid
europa.velocity = He[10].snelheid
ganymede.velocity = He[11].snelheid
callisto.velocity = He[12].snelheid
sun.massa = He[0].massa
earth.massa = He[3].massa
moon.massa = He[4].massa
mercury.massa = He[1].massa
venus.massa = He[2].massa
mars.massa =He[5].massa
phobos.massa = He[6].massa
deimos.massa = He[7].massa
jupiter.massa = He[8].massa
io.massa = He[9].massa
europa.massa = He[10].massa
ganymede.massa = He[11].massa
callisto.massa = He[12].massa
planets.extend((sun, earth, moon, mercurius, venus, mars, phobos, jupiter, io, europa, ganymede, calisto))
while True:
sleep(0.02)
for planet in planets:
a = calc_gravitational_acceleration(planet.massa, planet.pos)
planet.velocity -= a*dt
planet.pos += planet.velocity * dt`

Tkinter Entry's get function returns nothing

I'm trying to use an Entry widget to get the user's data and then print it.
Why is Tkinter Entry's get function returning nothing?
This didn't help me.
This is my code
message = ''
# start_chatting function
def start_chatting ():
global message
master2 = tk.Tk()
master2.geometry("1280x720")
master2.title("Messenger")
label = tk.Label(master2, text = "Messenger!!!",bg = '#1e00ff',fg ='yellow',width = 35, height = 5).place(x = 500, y = 0)
username_label = tk.Label(master2,text = usernames[position_counter],bg = '#91806d',fg ='white',width = 10, height = 2).place(x = 0, y = 100)
v = StringVar()
L1 = Label(master2, text = "Type your message : ").place(x=0, y = 680)
e = Entry(master2,textvariable = v)
e.insert(END, '')
e.pack()
e.place(x = 115, y = 680)
submit_button = Button(master2,text = "Submit",command = submit_f).place(x = 200, y = 680)
message = message+ v.get()
master2.mainloop()
#submit_f function
def submit_f ():
global message
print(message)
Keep in mind that this is a part of my code and not all of it.
Thanks in advance!
The function prints nothing beacause you have changed the message value in the current function where the entry box is defined.
So, when you write v.get(), it generally returns an empty text.The message variable needs to call every time when submit button is pressed. Hence, message variable should be changed inside submit_f() function.
Here's the Solution,
import tkinter
from tkinter import *
message = ''
# start_chatting function
def start_chatting ():
global v
master2 = Tk()
master2.geometry("1280x720")
master2.title("Messenger")
label = Label(master2, text = "Messenger!!!",bg = '#1e00ff',fg ='yellow',width = 35, height = 5).place(x = 500, y = 0)
username_label = Label(master2,text = usernames[position_counter],bg = '#91806d',fg ='white',width = 10, height = 2).place(x = 0, y = 100)
L1 = Label(master2, text = "Type your message : ").place(x=0, y = 680)
v = StringVar()
e = Entry(master2,textvariable = v)
e.insert(END, '')
e.pack()
e.place(x = 115, y = 680)
submit_button = Button(master2,text = "Submit",command = submit_f).place(x = 200, y = 680)
master2.mainloop()
#submit_f function
def submit_f ():
global message
message = message + " " + v.get()
print(message)
start_chatting()

python-pptx color legend not showing same colors as graph

This drives me nuts.
chart_AllData = slideref.shapes.add_chart(XL_CHART_TYPE.BAR_STACKED_100, x, y, cx, cy, chart_data)
chart = chart_AllData.chart
plot = chart.plots[0]
pointCount = 0
for answer in consolidatedAnswersList: # Looping over the answer codes
print('answer: ', answer)
catBar = plot.series[pointCount].points
for cat in catBar: # Looping over the categories (= the declarations)
fill = cat.format.fill
fill.solid()
colorString = ccpStatistics.gAnswerCodeColorDict.get(answer, 'FFFFFF')
r = int(colorString[0]+colorString[1], 16)
g = int(colorString[2]+colorString[3], 16)
b = int(colorString[4]+colorString[5], 16)
fill.fore_color.rgb = RGBColor(r , g , b)
print('setting ', answer, ' to ', colorString)
pointCount += 1
print(ccpStatistics.gAnswerCodeColorDict)
category_axis = chart.category_axis
category_axis.minor_tick_mark = XL_TICK_MARK.OUTSIDE
category_axis.tick_labels.font.italic = True
category_axis.tick_labels.font.size = Pt(12)
value_axis = chart.value_axis
value_axis.format.line.color.rgb = RGBColor(0 , 0 , 0)
value_axis.tick_labels.font.size = Pt(int(thisPageDict.get('SCALEFONTSIZE', ['18'])[0]))
value_axis.major_tick_mark = XL_TICK_MARK.OUTSIDE
value_axis.has_major_gridlines = True
value_axis.tick_labels.font.color.rgb = RGBColor(0,0,0)
value_axis.major_tick_mark.number_format = '0.0"%"'
chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.RIGHT
chart.legend.include_in_layout = False # set to true
chart.legend.font.color.rgb = RGBColor(0,0,0)
chart.legend.font.size = Pt(int(thisPageDict.get('LEGENDSIZE', ['12'])[0]))
plot.has_data_labels = True
data_labels = plot.data_labels
data_labels.position = XL_LABEL_POSITION.CENTER
data_labels.font.size = Pt(int(thisPageDict.get('LEGENDSIZE', ['10'])[0]))
data_labels.font.color.rgb = RGBColor(0x00, 0x00, 0x00)
The content of the ccpStatistics.gAnswerCodeColorDict is as follows:
{'oaq_NoAnswer': 'DCDCDC', 'maq_NoAnswer': 'DCDCDC', 'Answer code': 'Answer code color', '1': 'FF0000', '2': 'FF6600', '3': 'FFC301', '4': '00B050', 'OK': '00B050', 'NOK': 'FF0000', 'NA': '333333', 'NEU': 'FF00FF', 'maq': '3A87AD', 'dq': '660000', 'txta': '660000', 'nq': '660000'}
Now, the graph gets properly colored according to the settings in series... And the names of the series in the legend is OK too... But the colors of the legend does not correspond to the colors in the bar.
NOTE, similar code seems to work well in other methods. I'm at wit's end now.
See the resulting ppt chart
Try setting the color at the series level rather than at the individual point level.
fill = series.format.fill
fill.solid()
fill.fore_color.rgb = RGBColor(r, g, b)

Creating multiple files by changing values in a single file

I have a file named myfile.txt given below:
&cntrl
pTopt = 298.15, pdens = 0.997, prcut = 12.0, pion = t,
pihot = t, prQM = 5.5, prSM = 5.3, prQI=3.0, piguess = f,
pinit = t, pnstep = 5000, pnscale = 100,
pnstat = 5, pnout = 5, pnrst = 5, pioutc = t, pioutv = t, pnoutc=5,
pnoutv = 5,
msolute = t, nosa = 1, pichrg = t
gfileOut = 'as-1.out',
gfileEnout = 'as-1.en',
gfileInfo = 'as-1.info',
gfileStart = 'init.in',
gfileRst = 'as-1.rst',
gfileTraj = 'as-1.traj',
gfileVeloc = 'as-1.vel',
gfileQmen = 'as-1.qmen'
&end
Using the above given single file I want to create 10 files but I want to manipulate the values of last eight variables in a way that value of the variable in every new file changes as the number of file changes i.e if ten files are created then the value of last eight variables like gfileOut in tength file should be 'as-10.out'.
For doing this I have a code given below:
#!/usr/bin/python3
for i in range(10):
f = open('file' +str(i)+'.txt','w')
f.write("&cntrl pTopt = 298.15, pdens = 0.997, prcut = 12.0,pion=t,"+"\n"+
"pihot = t, prQM = 5.5, prSM = 5.3, prQI=3.0, piguess = f,"+"\n"+
"pinit = t, pnstep = 5000, pnscale = 100,"+"\n"+"pnstat = 5, pnout = 5,
pnrst = 5, pioutc = t, pioutv = t, pnoutc = 5, pnoutv = 5,"+"\n"+
"msolute = t, nosa = 1, pichrg = t"+"\n"+'gfileOut = as-' +str(i)+ ".out,"+"\n"+
'gfileEnout = as-' +str(i)+ '.en,'+"\n"+'gfileInfo = as-' +str(i)+".info,"+"\n"+
'gfileStart = init' +str(i)+ ".in,"+"\n"+'gfileRst = as' +str(i)+ ".rst,"+"\n"+
'gfileTraj = as' +str(i)+ ".traj,"+"\n"
+'gfileVeloc = as' +str(i)+ ".vel,"+"\n"+'gfileQmen = as' +str(i)+ '.qmen'+"\n"+"&end ")
f.close()
The above given code produces right output but I want a way to read myfile.txt and change the values of last eight variables as mentioned above and then use this file to create ten new files.
str.format handles the inserts into the string to be written to each of the files.
# Write the files.
for i in range(1, 11):
with open('file' +str(i)+ '.txt','w') as f:
f.write(
('&cntrl pTopt = 298.15, pdens = 0.997, prcut = 12.0, pion=t,\n'
'pihot = t, prQM = 5.5, prSM = 5.3, prQI=3.0, piguess = f,\n'
'pinit = t, pnstep = 5000, pnscale = 100,\n'
'pnstat = 5, pnout = 5, pnrst = 5, pioutc = t, pioutv = t, pnoutc = 5, pnoutv = 5,\n'
'msolute = t, nosa = 1, pichrg = t\n'
'gfileOut = as-{index}.out,\n'
'gfileEnout = as-{index}.en,\n'
'gfileInfo = as-{index}.info,\n'
'gfileStart = init{index}.in,\n'
'gfileRst = as{index}.rst,\n'
'gfileTraj = as{index}.traj,\n'
'gfileVeloc = as{index}.vel,\n'
'gfileQmen = as{index}.qmen\n'
'&end ').format(index=i))
Note: The string contains {index} which is replaced by the value of i that range(1, 10) sets.
Edit: Re-done post due to misunderstanding the details of the question alerted by the 1st comment. Sorry.
Edit: Looked at need to read from file, so this may help.
template.txt:
&cntrl pTopt = 298.15, pdens = 0.997, prcut = 12.0, pion=t,
pihot = t, prQM = 5.5, prSM = 5.3, prQI=3.0, piguess = f,
pinit = t, pnstep = 5000, pnscale = 100,
pnstat = 5, pnout = 5, pnrst = 5, pioutc = t, pioutv = t, pnoutc = 5, pnoutv = 5,
msolute = t, nosa = 1, pichrg = t
gfileOut = as-{index}.out,
gfileEnout = as-{index}.en,
gfileInfo = as-{index}.info,
gfileStart = init{index}.in,
gfileRst = as{index}.rst,
gfileTraj = as{index}.traj,
gfileVeloc = as{index}.vel,
gfileQmen = as{index}.qmen
&end
main script:
# Read template file.
with open('template.txt') as r:
content = r.read()
# Write the files.
for i in range(1, 11):
with open('file' +str(i)+ '.txt','w') as f:
f.write(content.format(index=i))

Resources