Jump to content

[SOLVED] Plot datafiles using Alfred and Python


Recommended Posts

**Question**

How to plot column0 vs column2 of a data file using Alfred and Python?

 

Shared Workflow

===============

 https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/python_plots/aa python plots.alfredworkflow?raw=true

 

Sample datafile: https://raw.githubusercontent.com/bhishanpdl/Shared/master/Alfred_questions/python_plots/data.txt

 

The given workflow reads the column0 vs column1 of the given data file and plots it.

Is it possible to make plot column0 vs column2 using arguments?

 

Required Method:

=============

1. selet the given file in Finder

2. double tap shift (open alfred3)

3. plot 0 2      # This should plot column0 vs column2

 

 

The python script used:

=================

import sys
import numpy as np 
import matplotlib.pyplot as plt

ifile = sys.argv[1]

x,y = np.genfromtxt(ifile,delimiter='',usecols=(0,1),\
                  comments='#',unpack=True,dtype=None).astype(np.float64)

plt.plot(x,y,'ro')
plt.xlabel('x')
plt.ylabel('y')
plt.xlim(min(x)*0.9, max(x)*1.1)
plt.ylim(min(y)*0.9, max(y)*1.1)
plt.show()

 

 

Problem:

========

I could not figure out how to pass the arguments to the python workflow when we select the file from the Finder.

 

 

Help will be appreciated. 

Edited by Bhishan
Link to comment
52 minutes ago, Bhishan said:

I could not figure out how to pass the arguments to the python workflow when we select the file from the Finder.

 

There are no arguments (apart from the filepath). You need to insert a Keyword or Script Filter between the File Action/Selection in macOS Hotkey and the Run Script that asks the user to enter them. And then you need to parse them in your script.

 

If you can't figure it out, let me know. I can't write you a demo right now because England is playing.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...