openpyxl - is it possible to change marker on linechart to None - openpyxl

I'm using openpyxl to modify my xlsx data i create few linecharts. I can't figure it out how to change Marker options on my chart to None. When graph is created Marker Options in xlsx is set to Automatic so I have a lot of dots on the line.
Tnaks for answers.

This is possible in openpyxl 2.3. The docs are still work in progress but you have full access to entire formatting API. Unfortunately, this API is hideously complex.
Code will look something like:
chart = LineChart()
# add some data
line = chart.series[0]
line.shapeProperties.line.noFill = True
line.marker.symbol = "circle"
See http://openpyxl.readthedocs.org/en/stable/charts/introduction.html to get a start (and checkout the 2.3 branch for more examples). For full control you will have to familiarise yourself with the OOXML specification and be prepared to read the source of your charts.

Related

#BFxForward() in the Bloomberg python api

I've used https://github.com/691175002/BLPInterface as a wrapper to the terribly-documented (and non-supported by Bloomberg Help) Bloomberg python API. I use it to pull price histories, etc.
Lately I've needed to pull specific FX date values. In excel I do that as =#BFxForward("usdjpy",J10, "BidOutright") where J10 is a date.
I would like to pull this information via the Bloomberg Python API (or even better, with the BLPInterace wrapper) but it's not clear how to do it. I've seen someone ask a similar question for a .Net implementation, but the only answer cited page 207 of a developers guide. Every developer guide I can find on bloomberg is well less than 200 pages, and none of it mentions pulling fx values.
Wondering if anyone can point me at some examples or resources to build on to get this ?
It does take some finding, to be sure, but I tracked it down via the Bloomi Terminal. The way I found the information is as follows (for future reference):
Type DAPI in the Bloomberg Terminal
Choose 'Additional Resources' in the left hand panel
Choose 'Help Page for DAPI' in the right hand panel, and a window pops up
Choose 'Constructing Formulas' in the left hand panel
Choose 'FX Broken Dates Forwards Syntax' in the right hand panel
Or paste this link into Bloomi:
{LPHP DAPI:0:1 2277846 }
There are a lot of different examples and options (FX fwds are not my area of expertise), but simply using this format for the ticker seems to work:
ccy1/ccy2 mm/dd/yy Curncy
and then the field PX_BID. You can try this in a BDP call in Excel, for example:
=BDP("EUR/GBP 08/08/22 Curncy","PX_BID")
When it comes to Python, perhaps try using the xbbg python package (other wrappers are available): it does a good job of hiding all the intricacies of the low-level API.
Here's a code sample using xbbg, that pulls back the forward fx rate in the example:
from xbbg import blp
from datetime import datetime
ccy1 = 'EUR'
ccy2 = 'GBP'
fwdDate = datetime(2022,8,8)
ticker = '{0:}/{1:} {2:} Curncy'.format(ccy1,ccy2,fwdDate.strftime('%m/%d/%y'))
df = blp.bdp(ticker,'PX_BID')
print(df)
Output:
px_bid
EUR/GBP 08/08/22 Curncy 0.85344
EDIT: Looking at the OP's choice of Bloomi wrapper, the xbbg call could possibly be replaced by:
blp.referenceRequest(ticker, 'PX_BID')

How to adapt tf.contrib.data.TextLineDataset for text from other sources?

For example, if my text data come from a database, how can I get one line/doc(as a database record) using the same mechanism (subclassing Dataset such that the pipeline described here still works) as TextLineDataset ?
By looking at the source code of TextLineDataset, I find that make_dataset_resource() seems an import method to be implemented. But I can't find where the actual code of yielding a line from a file as the docstring of TextLineDataset says: A Dataset comprising lines from one or more text files.

Edit a Mainframe file in the RecordEditor without a copybook

How do you Edit a (binary EBCDIC) Mainframe file in the RecordEditor with out a Cobol Copybook.
How do you generate Java code to read the file using the RecordEditor.
Note: This is an attempt to split a question that is far to broad to give meaningful answer to
into a series of simpler Question and Answer's.
Try and avoid editing a binary file with a Cobol Copybook if at all possible. This should only be attempted as a last resort !!!.
Try and get
that Cobol copybook (or some field layout document) for the file !!!
Some general advise:
It is feasible when dealing with 10 / 20 fields in a record but not if there a thousands of fields in a Record.
Take your time do not rush the process. Try and get each step correct before moving on
Finally upgrade to the latest version of the RecordEditor (currently 0.98.4)
This process will also work for normal Text file as well
RecordEditor Layout Wizard
To start the wizard select option Record Layouts >>> Layout Wizard.
File Structure screen
The file structure screen has 3 purposes:
Get the File structure - It could be Fixed Width, VB, Windows/Unix Text file
Get the Record-Length (if it is a fixed width file).
Get the font (character-set / encoding)
The RecordEditor will try and work this out for you
Field Selection Screen
The RecordEditor will try and work out where fields start and end but
it is not perfect. You need to carefully check and correct its choices
On this screen, the fields are displayed in alternating colors
you create/delete a field by clicking on
use the Clear Fields button clear all the fields
you can change what field-types to search for using the various check box's (e.g. Mainframe Zones Decimal)
The Add Fields will do another field search
Field Definition screen
On this screen you define the field names and Types. You may need to go back to the **Field Selection Screen* to adjust the fields
Editing the file
Once the Record Layout has been defined, it can be used on the open file screen
Generating Java code
When editing your file, you can generate java~JRecord code to read the file
by selecting Generate >>> Java >>> ....
You can the enter a package-id + generate options:
and finally your sample java code is generated to read / write the
file.

How to store data from Google Ngram API?

I need to store the data presented in the graphs on the Google Ngram website. For example, I want to store the occurences of "it's" as a percentage from 1800-2008, as presented in the following link: https://books.google.com/ngrams/graph?content=it%27s&year_start=1800&year_end=2008&corpus=0&smoothing=3&share=&direct_url=t1%3B%2Cit%27s%3B%2Cc0.
The data I want is the data you're able to scroll over on the graph. How can I extract this for about 140 different terms (e.g. "it's", "they're", "she's", etc.)?
econpy wrote a nice little module in Python that you can use through a command-line interface.
For your "it's" example, you would need to type this command in a terminal / windows console:
python getngrams.py it's -startYear=1800 -endYear=2008 -corpus=eng_2009 -smoothing=3
This will automatically save the query result in a CSV file named after your query parameters.
econpy's package, in #HugoMailhot's answer, no longer works (2021) and seems not maintained.
Here's a updated version, with some improvements for easier integration into Python code:
https://gitlab.com/cpbl/google-ngrams
You can call this from the command line (as in econpy's) to create a CSV file, e.g.
getngrams.py it's -startYear=1800 -endYear=2008 -corpus=eng_2009 -smoothing=3
or call it from python to get (and plot) data directly in python, e.g.:
from getngrams import ngrams
df = ngrams('bells and whistles -startYear=1900 -endYear=2018 -smoothing=2')
df.plot()
The xkcd functionality is still there too.
(Issues / bug fix pull requests /etc welcome there)

What scripting language would you use to put text over a generated image?

I got this question from my cousin:
"What will be the best way to create a similar working website just like: http://www.plakletters.nl".
I have looked into the website and think that to start of with i'm gonna help my cousin write a script that loads all fonts installed on the system into a dropdownlist. This dropdownlist will post a font value back to the page and will create images with the input of a user that comes from a textbox. This images will have to be created server side, and I also want to give the users the ability (in the future) to lay their own text over an uploaded image, to see what the result will look like on their own image. I found some information about how to create images using php, I don't know if php can output a list of installed fonts from the system it's running on. What scripting language would you use to get this job done? Keep in mind i would just like to start with outputting some images based on user input using a scripting language.
ImageMagick. This can be called from the shell or with the Perl bindings or with bindings for a lot of other languages. See http://www.imagemagick.org/Usage/text/
If you use perl, another alternative is the Imager module. This tends to be a simpler install than ImageMagick/PerlMagick.
Adding text looks like:
use Imager;
my $img = Imager->new(file => "foo.jpg") || die Imager->errstr();
my $font = Imager::Font->new(file=>"Arial.ttf");
$img->string(
x => 50, y => 70,
string => "Hello, World!",
font => $font, size => 30,
aa => 1, color => 'white'
);
$img->write(file => "foo2.jpg");
More details here.
Well, my favorite language is Python, so that's what I'd use! :) The PIL module gives you image manipulation capabilities.
Although I have never used PIL before, I put together the following with a few minutes of research and experimentation:
import Image
import ImageDraw
im = Image.open("my_image.png")
draw = ImageDraw.Draw(im)
draw.text((0,0), "my text")
im.save("my_out.png")
As you might have guessed, this just opens a PNG file, writes "my text" into it in the upper left corner and saves the modified image with a new name. I do not know how to get the font information you're looking for, but expect there's a module that can help with that also.