Thursday, 15 May 2014

python - matplotlib: subplot background (axes face + labels) colour [or, figure/axes coordinate systems] -



python - matplotlib: subplot background (axes face + labels) colour [or, figure/axes coordinate systems] -

i have figure containing 3x2 subplots, , set background colour on middle pair of subplots create clearer axis labels belong subplot.

setting facecolor when constructing subplot changes colour of area defined axes; tick , axis labels still drawn on figure.patch. assuming there no simple way this, add together rectangular patch behind relevant instances in figure.axes.

after bit of experimenting around, appears figure.axes[x].get_position() returns axes coördinates (normalised coördinates [0.0-1.0]), yet rectangle() appears want display coördinates (pixels). code more or less works (ed: interactively, when outputting png (using agg renderer), positioning of rectangle off):

import matplotlib.pyplot plt import matplotlib f = plt.figure() plt.subplot( 121 ) plt.title( 'model' ) plt.plot( range(5), range(5) ) plt.xlabel( 'x axis' ) plt.ylabel( 'left graph' ) plt.subplot( 122 ) plt.title( 'residuals' ) plt.plot( range(5), range(5) ) plt.xlabel( 'x axis' ) plt.ylabel( 'right graph' ) plt.tight_layout(pad=4) bb = f.axes[0].get_position().transformed( f.transfigure ).get_points() bb_pad = (bb[1] - bb[0])*[.20, .10] bb_offs = bb_pad * [-.25, -.20] r = matplotlib.patches.rectangle( bb[0]-bb_pad+bb_offs, *(bb[1] - bb[0] + 2*bb_pad), zorder=-10, facecolor='0.85', edgecolor='none' ) f.patches.extend( [r] )

but seems hackish, , feels i've missed out on important. can explain what, whether there simpler/better way it, , if so, is?

since need write file, presently don't have solution.

just utilize transform kwarg rectangle, , can utilize coordinate scheme you'd like.

as simple example:

import matplotlib.pyplot plt matplotlib.patches import rectangle fig, axes = plt.subplots(3, 2) rect = rectangle((0.08, 0.35), 0.85, 0.28, facecolor='yellow', edgecolor='none', transform=fig.transfigure, zorder=-1) fig.patches.append(rect) plt.show()

however, if wanted things more robustly, , calculate extent of axes, might this:

import matplotlib.pyplot plt matplotlib.transforms import bbox matplotlib.patches import rectangle def full_extent(ax, pad=0.0): """get total extent of axes, including axes labels, tick labels, , titles.""" # text objects, need draw figure first, otherwise extents # undefined. ax.figure.canvas.draw() items = ax.get_xticklabels() + ax.get_yticklabels() # items += [ax, ax.title, ax.xaxis.label, ax.yaxis.label] items += [ax, ax.title] bbox = bbox.union([item.get_window_extent() item in items]) homecoming bbox.expanded(1.0 + pad, 1.0 + pad) fig, axes = plt.subplots(3,2) extent = bbox.union([full_extent(ax) ax in axes[1,:]]) # it's best transform figure coordinates. otherwise, won't # behave correctly when size of plot changed. extent = extent.transformed(fig.transfigure.inverted()) # can create rectangle in figure coords using "transform" kwarg. rect = rectangle([extent.xmin, extent.ymin], extent.width, extent.height, facecolor='yellow', edgecolor='none', zorder=-1, transform=fig.transfigure) fig.patches.append(rect) plt.show()

python matplotlib

Inserting numeric data type using SQL statement in Java -



Inserting numeric data type using SQL statement in Java -

i writing method allows users store info within database.

the problem have storing numeric datatype in database, user's id.

firstly, how can tell if id number auto-incrementing? these it's properties:

type: numeric column size: 4 decimal digits: 0 part of primary key: true part of index: true position: 1

i'm sure read somewhere that, setting part of index (true) allows auto-incrementation. can confirm?

more importantly, when inserting info table receive error stating:

columns of type 'numeric' cannot hold values of type 'char'.

this snippet of insert code (i can reveal more if need be):

statement pstatement = conn.createstatement(); string selectsql = ("insert app.person values ('" + '3' + "','" + user + "','" + pass + "','" + fname + "','" + sname + "','" + squestion + "','" + sanswer + "') "); pstatement.executeupdate(selectsql);

as can see setting id (the first value), 3 manually. believe throwing error , know how insert numeric value, using insert command.

i coding in java, using netbeans 7.3 beta 2, on mac os x mount lion. using derby database.

hey bro suggest u utilize preparestatement

string template = "insert app.person values (your,table,collumn,name) values (?,?,?,?)"; preparedstatement stmt = yourconnection.preparestatement(template);

so if want set id integer, allow java with

stmt.setint(1, id); stmt.setstring(2, user); stmt.setstring(3, fname); stmt.executeupdate();

i dont know how table construction illustration if want utilize int utilize stmt.setint(1, 3);

1--> position u set in string template

3--> maybe u want hard coded id

here illustration pattern utilize preparestatement

string name = "shadrach" double cost = "100.00" int qty = 3; string template = "insert product (name,price,qty) values (?,?,?)"; preparedstatement stmt = connection.preparestatement(template); stmt.setstring(1, name); stmt.setdouble(2, price); stmt.setint(3, qty); stmt.executeupdate();

java sql numeric javadb

ios - Animating UITextInput's textInputView -



ios - Animating UITextInput's textInputView -

uikit text input components, such uitextview , uitextfield have property inputview add together custom keyboard. there 2 questions have relating this.

if keyboard visible , property set new input view, nil happens. resigning , regaining first responder status refreshes input , displays new view. best way it? if might reply bigger question:

is possible animate transition between 2 input views?

from uiresponder docs:

responder objects require custom view gather input user should redeclare property readwrite , utilize manage custom input view. when receiver subsequently becomes first responder, responder infrastructure presents specified input view automatically. similarly, when view resigns first responder status, responder infrastructure automatically dismisses specified view.

so unfortunately reply 1 yes , 2 no.

ios objective-c uitextfield uitextview uitextinput

Vb.Net get radio 1s nowplaying from json file in windows form -



Vb.Net get radio 1s nowplaying from json file in windows form -

now making radio programme , ive come across http://www.bbc.co.uk/radio1/developers/api/ have thought how implement in program. it's using .json file. know how using php shows loads stuff don't need nor know how use. , don't want host php page because hosting have slow times , constant pinging create slower. there way in program. grabbing .json bbc page. , json things "artist":, "image": , "title": give thanks in advance. oh im still in secondary school im not pro in vb.net

try using json.net (http://james.newtonking.com/projects/json-net.aspx) parse info .net classes , utilize resulting objects in vb application.

vb.net json winforms radio

html - How can I swap in and out text inside a DIV using only javascript? -



html - How can I swap in and out text inside a DIV using only javascript? -

i have text within div this:

<div> @*<p class="header">xxx</p> <p> yyy </p> <p> yyy </p>*@ <p class="header">xxx</p> <p> yyy </p> <p> yyy </p> </div>

i commented out first 3 paragraphs , replaced them sec three. there way create every 10 seconds changes between showing first 3 paragraphs , sec three. note don't utilize jquery on page. want find solution not utilize jquery.

without jquery:

put 2 groups of

in 2 div id.

document.getelementbyid('iddiv1').style.display = "none"; --> create invisibile div1 document.getelementbyid('iddiv2').style.display = "block"; --> create visibile div2

for create in automatic mode, have utilize timer function of javascript, here. link of w3school.

javascript html css

python 3.x - Modifying logging message format based on message logging level in Python3 -



python 3.x - Modifying logging message format based on message logging level in Python3 -

i asked question python 2 here, bumped issue 1 time again when the reply no longer worked python 3.2.3.

here's code works on python 2.7.3:

import logging # effort set python3 logger print custom messages # based on each message's logging level. # technique recommended python2 not appear work # python3 class customconsoleformatter(logging.formatter): """ modify way debug messages displayed. """ def __init__(self, fmt="%(levelno)d: %(msg)s"): logging.formatter.__init__(self, fmt=fmt) def format(self, record): # remember original format format_orig = self._fmt if record.levelno == logging.debug: self._fmt = "debug: %(msg)s" # phone call original formatter grunt work result = logging.formatter.format(self, record) # restore original format self._fmt = format_orig homecoming result # set logger my_logger = logging.getlogger("my_custom_logger") my_logger.setlevel(logging.debug) my_formatter = customconsoleformatter() console_handler = logging.streamhandler() console_handler.setformatter(my_formatter) my_logger.addhandler(console_handler) my_logger.debug("this debug-level message") my_logger.info("this info-level message")

a run using python 2.7.3:

tcsh-16: python demo_python_2.7.3.py debug: debug-level message 20: info-level message

as far can tell, conversion python3 requires slight mod customconsoleformatter.init():

def __init__(self): super().__init__(fmt="%(levelno)d: %(msg)s", datefmt=none, style='%')

on python 3.2.3:

tcsh-26: python3 demo_python_3.2.3.py 10: debug-level message 20: info-level message

can see, want replace '10' 'debug' beingness thwarted.

i've tried digging around in python3 source , looks percentstyle instantiation clobbering self._fmt after i, well, clobber myself.

my logging chops stop short of beingness able work around wrinkle.

can recommend way or perhaps point out i'm overlooking?

with bit of digging, able modify python 2 solution work python 3. in python2, necessary temporarily overwrite formatter._fmt. in python3, back upwards multiple format string types requires temporarily overwrite formatter._style._fmt instead.

# custom formatter class myformatter(logging.formatter): err_fmt = "error: %(msg)s" dbg_fmt = "dbg: %(module)s: %(lineno)d: %(msg)s" info_fmt = "%(msg)s" def __init__(self): super().__init__(fmt="%(levelno)d: %(msg)s", datefmt=none, style='%') def format(self, record): # save original format configured user # when logger formatter instantiated format_orig = self._style._fmt # replace original format 1 customized logging level if record.levelno == logging.debug: self._style._fmt = myformatter.dbg_fmt elif record.levelno == logging.info: self._style._fmt = myformatter.info_fmt elif record.levelno == logging.error: self._style._fmt = myformatter.err_fmt # phone call original formatter class grunt work result = logging.formatter.format(self, record) # restore original format configured user self._style._fmt = format_orig homecoming result

and here halloleo's illustration of how utilize above in script (from python2 version of question):

fmt = myformatter() hdlr = logging.streamhandler(sys.stdout) hdlr.setformatter(fmt) logging.root.addhandler(hdlr) logging.root.setlevel(debug)

logging python-3.x

javascript - Iterate through Array of Objects using Dustjs -



javascript - Iterate through Array of Objects using Dustjs -

after jsonp phone call returned:

[ { "text": "yo whats up?", "id": 1 }, { "text": "hey man!", "id": 2 }, { "text": "dude.", "id": 3 } ]

heres actual api call: http://api.twitter.com/1/statuses/user_timeline/codinghorror.json

using dust.js like:

<ul> {#myposts} <li>{text}, {id}{~n}</li> {:else} <p>humm...</p> {/myposts} </ul>

but there no key "myposts" in response. that's problem. checkout api phone call see how json beingness returned, mabye i'm interpreting wrong.

what syntax utilize in dust.js iterate through each object in array?

you can utilize "current context" shortcut.

{#.} {text} - {id}<br /> {/.}

javascript json dust.js