Python Help: Plots are not appearing in the Spyder Console
0
0
Entering edit mode
5.2 years ago
WUSCHEL ▴ 810

I am going to analyze proteomics data in Python/Spyder. I did run below scripts in Jupyter and it did work fine. Why don't plots appear in the spyder console? Do these libraries only specific to Jupyter? What should I have to follow to get the scripts in Spyder

data

structure(list(Protein = structure(3:1, .Label = c("AOX", "Ppt", 
"Sdx"), class = "factor"), Peptide = structure(c(2L, 1L, 3L), .Label = c("EIEYPGQVLR", 
"GLAEFQQK", "TNTDFLPYNGDGFK"), class = "factor"), location = structure(c(2L, 
3L, 1L), .Label = c("Golgi", "Mito", "PEX"), class = "factor"), 
    WT_0t_1 = c(5204L, 5151L, 1135L), WT_0t_2 = c(2794L, 4256L, 
    656L), WT_0t_3 = c(1981L, 3270L, 449L), WT_1t_1 = c(4202L, 
    71366L, 9121L), WT_1t_2 = c(2382L, 44102L, 5389L), WT_1t_3 = c(2190L, 
    55854L, 6719L), WT_3t_1 = c(2060L, 51214L, 9330L), WT_3t_2 = c(2227L, 
    52466L, 9325L), WT_3t_3 = c(1829L, 85549L, 10915L), WT_5t_1 = c(1803L, 
    32629L, 7034L), WT_5t_2 = c(1683L, 38552L, 7947L), WT_5t_3 = c(2501L, 
    83839L, 10031L), wus2_0t_1 = c(4199L, 1604L, 1L), wus2_0t_2 = c(5443L, 
    5550L, 831L), wus2_0t_3 = c(5493L, 4509L, 870L), wus2_1t_1 = c(4540L, 
    18298L, 2863L), wus2_1t_2 = c(3105L, 9892L, 1660L), wus2_1t_3 = c(3801L, 
    15808L, 2550L), wus2_3t_1 = c(2822L, 51167L, 5752L), wus2_3t_2 = c(2286L, 
    26685L, 4859L), wus2_3t_3 = c(2596L, 25978L, 4894L), wus2_5t_1 = c(2058L, 
    22977L, 2619L), wus2_5t_2 = c(2068L, 20512L, 2681L), wus2_5t_3 = c(2309L, 
    27932L, 5662L), wus5_0t_1 = c(4573L, 2731L, 254L), wus5_0t_2 = c(6558L, 
    3924L, 0L), wus5_0t_3 = c(6618L, 4635L, 861L), wus5_1t_1 = c(6235L, 
    30751L, 4703L), wus5_1t_2 = c(2866L, 14198L, 2944L), wus5_1t_3 = c(4997L, 
    22038L, 3930L), wus5_3t_1 = c(2939L, 26945L, 4571L), wus5_3t_2 = c(4872L, 
    41267L, 4442L), wus5_3t_3 = c(4129L, 36632L, 6963L), wus5_5t_1 = c(3966L, 
    58892L, 10088L), wus5_5t_2 = c(2933L, 77223L, 7056L), wus5_5t_3 = c(2799L, 
    42703L, 8511L), wus7_0t_1 = c(4202L, 6298L, 311L), wus7_0t_2 = c(1871L, 
    3735L, 413L), wus7_0t_3 = c(2076L, 2092L, 193L), wus7_1t_1 = c(3492L, 
    19426L, 1586L), wus7_1t_2 = c(2659L, 18379L, 3616L), wus7_1t_3 = c(3097L, 
    22991L, 1806L), wus7_3t_1 = c(839L, 26725L, 4855L), wus7_3t_2 = c(3309L, 
    68651L, 7717L), wus7_3t_3 = c(2215L, 28616L, 4207L), wus7_5t_1 = c(776L, 
    26765L, 6191L), wus7_5t_2 = c(2460L, 105244L, 9085L), wus7_5t_3 = c(2431L, 
    97977L, 10984L), wus9_0t_1 = c(3152L, 4976L, 682L), wus9_0t_2 = c(3253L, 
    3826L, 0L), wus9_0t_3 = c(2818L, 5648L, 423L), wus9_1t_1 = c(1024L, 
    11057L, 2741L), wus9_1t_2 = c(2093L, 17916L, 1855L), wus9_1t_3 = c(1743L, 
    13561L, 2047L), wus9_3t_1 = c(2406L, 46471L, 6354L), wus9_3t_2 = c(1709L, 
    41807L, 4243L), wus9_3t_3 = c(2490L, 59844L, 6709L), wus9_5t_1 = c(2084L, 
    50857L, 8948L), wus9_5t_2 = c(1217L, 33163L, 6777L), wus9_5t_3 = c(1173L, 
    102291L, 13028L)), class = "data.frame", row.names = c(NA, 
-3L))

I have used below scripts for plotting, which perfectly work in Jupyter.

df.loc[df.location == 'Cytolsol_ribo', 'location'] = 'Cytosol_ribo'
df = df[df.location != 'Median']

df2 = df2.set_index(['location'])

df2 = df2.stack().to_frame()

df2 = df2.reset_index()

df2.columns = ['location', 'exp', 'val']
df2['mutant'], df2['time'], df2['replicate'] = df2.exp.str.split('_').str

df2 = df2.drop('exp', axis=1)
df2 = df2[['location', 'mutant', 'time', 'replicate', 'val']]

box_opts = opts.BoxWhisker(height=400,
                           width=700,
                           show_legend=False,
                           whisker_color='gray',
                           box_color=hv.dim('time'),
                           box_cmap='Category10')

g = df2.hvplot.box( y='val', by=['mutant', 'time'], groupby='location')

g.opts(box_opts)

I do not get the plots in the Spyder console. What may be the reason?

Python Omics • 8.0k views
ADD COMMENT
1
Entering edit mode

I am not familiar with Spyder. But if the plotting is done by matplotlib under the hood, I guess you may use plt.show() to visualize it. https://matplotlib.org/api/_as_gen/matplotlib.pyplot.show.html?highlight=show#matplotlib.pyplot.show

ADD REPLY
0
Entering edit mode

Thanks, shoujun. I had a look. it doesn't work, unfortunately.

ADD REPLY
0
Entering edit mode

looks like hvPlot using Bokeh under the hood. You may try something like: bokeh.plotting.show(g)

ADD REPLY
0
Entering edit mode

No luck shoujun, dosn't work

bokeh.plotting.show(g)
Traceback (most recent call last):

  File "<ipython-input-74-49d321d018a1>", line 1, in <module>
    bokeh.plotting.show(g)

NameError: name 'bokeh' is not defined
ADD REPLY
1
Entering edit mode

have you installed and imported bokeh?

ADD REPLY
0
Entering edit mode

Yes, But still I do not see plots appearing in the console

ADD REPLY

Login before adding your answer.

Traffic: 1392 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6