Python help: Paths in gmplot - python

I can’t find any documentation on using paths in gmplot. I came up with this code which gets close, but it connects all of the lines and fills it in with a color - I don't want that.
I simply want a path like this:
http://imgur.com/3iaC2NQ
But, what I’m getting is this:
http://imgur.com/ypXEqof
Heres’s my code:
pathlon = -117.2974695,-117.2980671,-117.2984607,-117.2979182,-117.2974082,-117.2966604,-117.2977518,-117.2987498,-117.2981491,-117.297708,-117.2972804,-117.2965301,-117.2979485,-117.2975028,-117.2980506,-117.2982983,-117.2976609,-117.2970861,-117.2969908,-117.2981731,-117.2987695,-117.2981146,-117.2976909,-117.2969674,-117.2969299,-117.298394
pathlat = 33.27172039,33.27197757,33.27217535,33.27225324,33.27218351,33.27233921,33.27242614,33.27248971,33.27268346,33.27265944,33.27263664,33.27279608,33.27281652,33.27194103,33.27176546,33.27224514,33.27222714,33.27208829,33.27237357,33.27243373,33.27262189,33.27268296,33.27265933,33.27262125,33.27282274,33.27283925
gmap = gmplot.GoogleMapPlotter(pathlat[0],pathlon[0],18)
gmap.polygon(pathlat,pathlon,edge_color="cyan", edge_width=5, face_color=None, face_alpha=None, clickable = False)
gmap.draw('map.html')
Hoping someone can point me in the right direction.
Thanks in advance!

Since you are using polygon, this is the expected consequence. You should use plot method.
Please see following part;
pathlon = -117.2974695,-117.2980671,-117.2984607,-117.2979182,-117.2974082,-117.2966604,-117.2977518,-117.2987498,-117.2981491,-117.297708,-117.2972804,-117.2965301,-117.2979485,-117.2975028,-117.2980506,-117.2982983,-117.2976609,-117.2970861,-117.2969908,-117.2981731,-117.2987695,-117.2981146,-117.2976909,-117.2969674,-117.2969299,-117.298394
pathlat = 33.27172039,33.27197757,33.27217535,33.27225324,33.27218351,33.27233921,33.27242614,33.27248971,33.27268346,33.27265944,33.27263664,33.27279608,33.27281652,33.27194103,33.27176546,33.27224514,33.27222714,33.27208829,33.27237357,33.27243373,33.27262189,33.27268296,33.27265933,33.27262125,33.27282274,33.27283925
gmap = gmplot.GoogleMapPlotter(pathlat[0],pathlon[0],18)
gmap.plot(pathlat,pathlon,'cornflowerblue', edge_width=10)
gmap.draw('map.html')

Related

Python Excel copy cell style from one to another openpyxl

I am struggling with the following using openpyxl version 3.0.7
I want to copy the style of one cell to another. That means, background colour, font, etc.
However, I don't know how I can do that.
My initial idea was basically to do
sheet["E1"].font = sheet["D1"].font.
That bit shoots out TypeError: unhashable type: 'StyleProxy'.
Using just .style doesn't really do all that much so it's not suitable.
I found a few solutions online like the one from here. However, I don't know how I can apply it to my specific needs seeing as I struggle to even transfer the font from one cell to another.
Shortly after typing this out, I found the solution.
from copy import copy
wb = openpyxl.load_workbook('C:\\path...\\')
sheet = wb["Name of the worksheet"]
sheet["E1"].font = copy(sheet["D1"].font)
sheet["E1"].border = copy(sheet["D1"].border)
sheet["E1"].fill = copy(sheet["D1"].fill)
sheet["E1"].number_format = copy(sheet["D1"].number_format)
sheet["E1"].protection = copy(sheet["D1"].protection)
sheet["E1"].alignment = copy(sheet["D1"].alignment)
The only thing left to do would be to do this in a loop. That would be achievable by doing something like
for i in range(....):
sheet["E" + str(i)].font= copy(sheet["D" +str(i)].font)
etc.

Gradient markup with Gspread Formatting

I am using Gspread Formatting to set background color to cells in Google Sheets.
Now I want to use the GradientRule to accomplish this:
Conditional formatting with GradientRule
I know I have to set a "minpoint" and a "maxpoint", but I am not sure how to do this.
This is what I got so far:
def color():
spr = client.open("Kleurtjes")
sheet = spr.worksheet("Tab3")
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
GradientRule=GradientRule(
minpoint(format=CellFormat(backgroundColor=Color(255,255,255)), type='number'),
maxpoint(format=CellFormat(backgroundColor=Color(0,128,0)), type='number')
)
)
rules = get_conditional_format_rules(sheet)
rules.append(rule)
rules.save()
Can you help me out?
Many thanks in advance!
I believe your goal as follows.
You want to achieve the following situation. (The image is from your question.)
Modification points:
You can see the script of GradientRule() and InterpolationPoint() at here and here, respectively.
At ConditionalFormatRule(), it seems that the AddConditionalFormatRuleRequest of the batchUpdate method in Sheets API is used. In this case, the color is required to be set from 0 to 1. Please be careful this.
When above points are reflected to your script, it becomes as follows.
Modified script:
Please modify your script as follows.
From:
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
GradientRule=GradientRule(
minpoint(format=CellFormat(backgroundColor=Color(255,255,255)), type='number'),
maxpoint(format=CellFormat(backgroundColor=Color(0,128,0)), type='number')
)
)
To:
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
gradientRule=GradientRule(
maxpoint=InterpolationPoint(color=Color(1, 1, 1), type='MAX'),
minpoint=InterpolationPoint(color=Color(0, 128 / 255, 0), type='MIN')
)
)
Note:
In this modification, it supposes that you have already been able to get and put values for Google Spreadsheet by using Sheets API with gspread and gspread_formatting. Please be careful this.
When you want to achieve the colors of above your image, for example, how about minpoint=InterpolationPoint(color=Color(0.34117648, 0.73333335, 0.5411765), type='MIN')?
References:
AddConditionalFormatRuleRequest
Color
gspread-formatting

How to update Span (Bokeh) using ColumnDataSource?

I am trying to update Span using ColumnDataSource, but the information is not being passed onto the source. Span unfortunately does not have a paremeter "source", so is there a better way?
I have defined my sources, figure and line like so:
m1_source = ColumnDataSource(data=dict(x1=[], y1=[]))
m1_spans = ColumnDataSource(data=dict(x1=[]))
p = figure(x_axis_type="datetime", title="", sizing_mode="fixed", height = 500, width = 1400)
p.line(x ="x1", y="y1", color = 'blue', source=m1_source)
Then I have a for loop that should ideally plot multiple spans, each 'i' will be a separate timestamp:
for i in m1_spans.data['x1']:
p.add_layout(Span(location=i, dimension='height', line_color='red', line_dash='solid', line_width=1))
This is taken from my update() function:
m1_source.data = dict(
x1=machine_1_vals['mpTimestamp'],
y1=machine_1_vals['Value'])
m1_spans.data = dict( x1=ToolsDF.loc[ToolsDF['Value'] == float(vals['Tool_val'])]['Timestamp'])
I have checked this, and m1_spans does successfully return multiple timestamps, so the error shouldn't be here.
The reason I am confused, is because my p.line will successfully update with no issues, but it does have a source parameter, while span does not.
I would be really appreciative for any advice about how to solve this issue.
If I should have supplied more information, I apologize and can update as needed, I just tried to keep it brief for you.
Thanks.
Span objects do not currently have an ability to be "powered" by a ColumnDataSource. Each Span only draws one span, specified by its own location property.
You will need to update the location property individually on each Span object in order to update it. Alternatively, if you absolutely want to be able to drive updates through a CDS, you could look at using a multi_line, segment, or ray glyph instead. Those all have different ways to configure their coordinates, so you'd have to see which is most convenient to your use-case. But they all come with one trade-off, which is that none of them have the full "infinite extent" that a Span supports.

Having trouble playing music using IPython

I have the lines of code
import IPython
IPython.display.Audio(url="http://www.1happybirthday.com/PlaySong/Anna",embed=True,autoplay=True)
And I'm not really sure what's wrong. I am using try.jupyter.org to run my code, and this is within if statements. The notebook is also taking in user inputs and printing outputs. It gives no error, but just doesn't show up/start playing. I'm not really sure what's wrong.
Any help would be appreciated. Thanks!
First you should try it without the if statement. Just the two lines you mention above. This will still not work, because your URL does point to an HTML page instead of a sound file. In your case the correct URL would be 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'.
The Audio object which you are creating, will only be displayed if it is the last statement in a notebook cell. See my Python intro for details. If you want to use it within an if clause, you can use IPython.display.display() like this:
url = 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'
if 3 < 5:
IPython.display.display(IPython.display.Audio(url=url, autoplay=True))
else:
print('Hello!')

Range for vertical bar chart with google chart-wrapper

I've been trying to figure out how to use google chart-wrapper with my django application but I can't seem to find hardly any documentation on how to use it. After playing around with it for awhile I got it to do most everything I want it to, but I can't seem to figure out how to get the range quite right.
For example, this url:
http://chart.apis.google.com/chart?chxt=x&chd=t:2.0,1.0,192.0,1032.0,22.0,60.0,75.0,94.0,3.0,2.0,1.0,11.0,383.0,3.0,164.0,50.0,12.0,5.0,564.0,7671.0,115.0,331.0&chm=N%2A,000000,0,-1,11&chs=1000x300&cht=bvs&chtt=Failure+Types&chxl=0:|B16|B13|B10|C11|A10|A13|D04|D03|D02|B01|C09|B05|B04|B07|C01|C03|C04|C07|A02|A01|A06|A05
has several values above 100 (in the chd section of the url), but when it gets rendered it cuts anything above 100 off.
This is the code I used to create that url:
hist = {}
d = Defect.objects.all()
for defect in d:
c = Failure.objects.filter(defect = defect).count()
if c > 0:
hist[defect.defcode] = c
m = VerticalBarStack(hist.values())
m.title("Failure Types")
m.size(1000,300)
m.marker('N*', 'black', 0, -1, 11)
m.axes('x')
m.axes.label(0, '|'.join(hist.keys()))
It seems logical that google chart-wrapper would allow me to write something along the lines of m.range(1000) or something similar to specify the range to show on the chart, but that doesn't work and I can't find any real documentation or detailed, complex enough examples to figure it out.
You should add scaling for extended encoding.
I have added the required parameters, as below:
chds=0,2000
your final URL is:
http://chart.googleapis.com/chart?chxt=x&chd=t:2.0,1.0,192.0,1032.0,22.0,60.0,75.0,94.0,3.0,2.0,1.0,11.0,383.0,3.0,164.0,50.0,12.0,5.0,564.0,7671.0,115.0,331.0&chm=N%2A,000000,0,-1,11&chs=500x500&cht=bvs&chds=0,2000&chtt=Failure+Types&chxl=0:|B16|B13|B10|C11|A10|A13|D04|D03|D02|B01|C09|B05|B04|B07|C01|C03|C04|C07|A02|A01|A06|A05

Categories