Skip to content

Commit

Permalink
Merged changes from Master branch, Moved Executor Parameters to Config (
Browse files Browse the repository at this point in the history
#163)

* Merging Recent SQL Executor changes

* Fix to Validator

Uses unique value metadata to verify if a value is valid

* Fix Bug with Widget Rendering

frame.py was trying to import luxWidget instead of luxwidget

* Added Number of Observations to MetaData, Fixed Interestingness issue with SQL Executor

Some interestingness functions required the number of observations in the data and visualization, so I added these values to the metadata to make the scoring work when using the SQL executor

Added tests for SQL executor

* Re-added Licensing Headers

* Adding Recent frame.py changes

* Adjusted SQL Executor Tests

Removed lines that changed Year column type to datetime

* Update Frame with new Action Registering

* Resolving Conflicts in frame.py

* Commenting out local SQL Executor tests

SQL Executor tests interfering with travis build, commenting out for now

* Update correlation.py

* Update frame.py

* bugfix: "number of remaining bars" text overcounts for colored bar charts
* update number of bars calculation to account for when len(data) double counts

* Fixing Code Format

* Cleaning up Pandas Executor imports

* Fix Validation Bug

Issue where validator was relying on metadata which was not yet generated, moved metadata calculation before validation step in frame.py

* Changed metadata variable name

Renamed num_obs to length, removed ordinal variable from Executor mapping function

* Adding support for setting intent on front end (#112)

* added functionality to delete Vis

* fixed deletion logic

* add observer to automatically update deletions

* able to refresh widget on setting intent

* support for setting intent from frontend

* quick fix to output

* changed variable intentindex name

* Make default_display a global setting (#121)

* remove and register action functions

* update changes inframe.py

* update changes inframe.py

* add documentation and changes

* indentation and comments

* new line

* globally defined default display works with warning

* no examples

* add back space

* new line

* uncomment docstring

Co-authored-by: Caitlyn Chen <caitlynachen@berkeley.edu>

* Added script to generate Postgresql database

Updated travis.yml file to create postgresql database in test instance.

Added script to populate test database with data.

* Update upload_car_data.py

Updated database credentials

* Updated script name in travis.yml

* Removed unnecessary import from travis.yml

* Added psycopg2 to requirements.txt

* Creating Postgres test database in travis

* Fixed directory issue

* Updated SQL Executor Tests

Added tests for basic SQL Executor functionality.

* Update requirements.txt (#128)

* basic scatterplot experiments

* experiment results with manually binned heatmaps

* experiment result

* incorporated heatmap code into executor and renderer

* additional experiments to evaluate scatter v.s. heatmap performance

* experiment based on real estate and airbnb data

* modified general sampling criteria, suppress SettingWithCopyWarning stemming from groupby .agg (#93)

* decrease sampling parameter

* change sampling strategy (above threshold keep 3/4 of data)

* remove experiment dir

* modified performance param

* enforce lux-widget minimum version

* update requirement.txt

* separate dev and install requirements

* replaced _exportedVisIdxs --> _selectedVisIdxs

* bugfix: plot config error when current_vis is None

* Added sql_executor example notebook, minor bug fix

Added an example notebook to showcase how to use the sql-engine.

Fixed variable reference in interestingness.py that was causing issues.

* Add LuxSeries Implementation (#122)

* add preliminary groupby fixes

* preliminary LuxSeries implementation

* add tests for new Series implementation

* clean up the added code

* minor code changes

* fix issues with Vis with index

* small fixes

* remove comments

* bugfix column group display empty Vis involving groupby index

* bugfix Cylinders not showing up as bar charts

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* add black to travis (#127)

* add black to travis

* reformat all code and adjust test

* remove .idea

* fix contributing doc

* small change in contributing

* update

* reformat, update command to fix version

* remove dev dependencies

* fix doc failing from black format

* Cleaned SQL Executor Example Notebook

restarted kernel and cleared output

* Update custom action reference to executor

Now uses executor tied to the dataframe for execution

* Updated Interestingness Tests (#133)

* add black

* update cars dataset and tests

* Delete old dataset

* Updated Interestingness Tests

Updated tests to use the newly updated cars dataset

* switch to local cars reference

Co-authored-by: Kunal Agarwal <kagarwal2@berkeley.edu>
Co-authored-by: Kunal Agarwal <32151899+westernguy2@users.noreply.github.com>
Co-authored-by: 19thyneb <thyne.boonmark@gmail.com>
Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* fix broken link in docs

* Updated Tests, Added benchmarking for SQL Executor

Updated Compiler and Interestingness tests to work for SQL executor.

Updated SQL Executor to have some benchmarking code for tracking query performance.

* Merge with upstream branch, added preliminary benchmarking code

* Better warning message for Vis and VisList (#135)

* added functionality to delete Vis

* fixed deletion logic

* add observer to automatically update deletions

* able to refresh widget on setting intent

* support for setting intent from frontend

* quick fix to output

* changed variable intentindex name

* added better error msg for > 1 intent for vis

* reverting some changes

* adding warning message for Vis intents being > 1

* passes tests and intent < 3

* minor change to error message, added test

* run black

* accounted for more edge cases and hid traceback

* fixed typo

* added tests

* format w/ black

* ran black again

* Update Vis.py

minor readability changes

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Pandas rewrite Performance optimizations  (#136)

* basic scatterplot experiments

* experiment results with manually binned heatmaps

* experiment result

* incorporated heatmap code into executor and renderer

* additional experiments to evaluate scatter v.s. heatmap performance

* experiment based on real estate and airbnb data

* modified general sampling criteria, suppress SettingWithCopyWarning stemming from groupby .agg (#93)

* decrease sampling parameter

* change sampling strategy (above threshold keep 3/4 of data)

* remove experiment dir

* modified performance param

* enforce lux-widget minimum version

* update requirement.txt

* testing out modin (Recursion error)

* create modin executor, all else in sync with master changes

* rewrote .loc with column reference, speed up by 100x

* replace agg("count") with .count() --> ~0.1ms speedup

* run black

* Added 2D Binning functionality to SQL Executor

added 2D binning to replace scatterplots when using SQL executor.

* Update README.md

update slack link

* Updated temporal detection and tests (#139)

* Updated temporal detection and tests

* Reformatted code with black

* Update PandasExecutor.py

* added stock date test

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Fix Inline comments breaking to new lines (#137)

* add black to travis

* reformat all code and adjust test

* remove .idea

* fix contributing doc

* small change in contributing

* update

* reformat, update command to fix version

* remove dev dependencies

* first pass -- inline comments

* _config/config.py

* delete test notebook

* action

* line length 105

* executor

* interestingness

* processor

* vislib

* tests, travis, CONTRIBUTING

* .format
() changed

* replace tabs with escape chars

* update using black

* more rewrites and merges into single line

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Improve warning message when values specified as attributes (#143)

* Improve warning message when values specified as attributes (#142)

* added test, ran black

* bugfix test

* Better warning message for Vis and VisList (#146)

* added functionality to delete Vis

* fixed deletion logic

* add observer to automatically update deletions

* able to refresh widget on setting intent

* support for setting intent from frontend

* quick fix to output

* changed variable intentindex name

* added better error msg for > 1 intent for vis

* reverting some changes

* adding warning message for Vis intents being > 1

* passes tests and intent < 3

* minor change to error message, added test

* run black

* accounted for more edge cases and hid traceback

* fixed typo

* added tests

* format w/ black

* ran black again

* Update Vis.py

minor readability changes

* added check and tests for Vis list and | syntax

* ran black

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Updated docs for JupyterLab (#148)

* added functionality to delete Vis

* fixed deletion logic

* add observer to automatically update deletions

* able to refresh widget on setting intent

* support for setting intent from frontend

* quick fix to output

* changed variable intentindex name

* added better error msg for > 1 intent for vis

* reverting some changes

* updated install and faq

* added install_lab.sh script

* Global shared variable in test (#144) (#149)

* using global shared variable in test (#144)

* modified fixture scope as session, resolved dependency test cases

* run black

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Updated 2D Binning Functionality

Interestingness function now compatible with 2D binning with SQL Executor. Fixed issue where some datapoints in heatmap data were of string type instead of integer.

* documentation for custom actions (#134)

* documentation for custom actions

* fix config tests

* fix documentaion links

* Add default display Config Class documentation

* delete hpi

* doc resolved changes

Co-authored-by: Caitlyn Chen <caitlynachen@berkeley.edu>
Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Patch failing test (#134)

* Patch failing test (#134)

* Patch failing test (#134)

* Added Heatmap generation to SQL Executor, Bug fix in PandasExecutor

Added 2D Binning function to collect data for heatmaps in the SQL Executor and updated compiler test to reflect heatmap changes in SQL Executor

Fixed issue within PandasExecutor where 2D binning function would not color heatmap using temporal variables

* Updated Code Formatting with Black

* Update Requirements to include psycopg2

* Update upload_car_data.py

Updated to use newest car.csv file

* Update Compiler tests to use correct test DB

* Removed Benchmarking Code

* Fixing Black Formatting

* Add Toggle button for LuxSeries (#153)

* add black

* add groupby to history

* add LuxSeries visualization implementation

* remove groupby extending

* run black

* merge master into branch

* run black

* Reformat Warnings Labels (#151)

* add format for warnings

* fix small details

* globally defined lux

* fix formatting

* Delete similarity.py

* Rename similarity_old.py to similarity.py

* fix commit

* update master with changes to warning labels

* fix formatting

Co-authored-by: Caitlyn Chen <caitlynachen@berkeley.edu>

* Make plot_config a global variable (#152)

* plot_config made global config

* docs and tests updates; black formatting

* Delete Untitled.ipynb

* cleanup

* remove data encapsulation

* black formatting

* Update style.rst

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Patch documentation (#134)

* code cleanup
* making LuxDataFrame pickle-able
* various simplification and rewrite to Compiler and Vis
* changing `render_VSpec` to `to_code`
* bugfix in filter (list comprehension lazily evaluated)

* Moved Executor Parameters to Global Config

* Black formatting

* Fix issue with read_json and add tests for different file types (#156)

* fix read_json bug and add tests

* convert tests to reference lux-datasets

* run black

* remove comments

* Update __init__.py

* Update test_pandas_coverage.py

new_df --> df

* fix tests to work with lux-datasets

* fix init

* remove lxml dependency

* remove html test

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Improved warning message stack trace for unexpected error (#145)

* Moved table_name parameter to frame.py. Removed executor_type parameter

executor_type parameter no longer necessary to maintain

* Fixed reference to table_name parameter

table_name is now a parameter within frame.py

* bug fix patching #146 (#159)
* remove sys.tracebacklimit to avoid `ERROR:root:Internal Python error in the inspect module`
* changed SyntaxError to TypeError to reserved SyntaxError for Pandas native syntax problems

* Ensure that recommendation and current_vis properties are accessible before df first printed (#159)

* bugfix erased `name` dtype in LuxSeries (#140)

* Adjusted Functions to Set SQL Connection

Moved set_SQL_connection function to config. Added set_SQL_table function within frame.py to let users specify which database table will be associated with their dataframe

* Update Makefile and pyproject.toml (#160)

* add black to travis

* reformat all code and adjust test

* remove .idea

* fix contributing doc

* small change in contributing

* update

* reformat, update command to fix version

* remove dev dependencies

* first pass -- inline comments

* _config/config.py

* delete test notebook

* action

* line length 105

* executor

* interestingness

* processor

* vislib

* tests, travis, CONTRIBUTING

* .format
() changed

* replace tabs with escape chars

* update using black

* more rewrites and merges into single line

* update pyproject.toml and makefile

* updating contributing doc

* Update CONTRIBUTING.md

Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>

* Update README.md

* Update SQLExecutor name parameter

* Merging master branch with sql engine. Moving executor parameters to config

* Parameter Bug Fix

Lux DataFrame current_vis should be an empty list after recs are expired.

Executor name for small_df and very_small_df checks should be "PandasExecutor"

* Reference Fix in Warning

Executor check here should look for name "PandasExecutor"

* Black Formatting

* Black formatting

* Cleaned up executor imports, Fixed issue in AltairRenderer

Issue where Altair Renderer was not using lux.config.executor

* Black formatting

Co-authored-by: 19thyneb <thyne.boonmark@gmail.com>
Co-authored-by: Doris Lee <dorisjunglinlee@gmail.com>
Co-authored-by: cjachekang <47467363+cjachekang@users.noreply.github.com>
Co-authored-by: Caitlyn Chen <caitlynachen@gmail.com>
Co-authored-by: Caitlyn Chen <caitlynachen@berkeley.edu>
Co-authored-by: Kunal Agarwal <32151899+westernguy2@users.noreply.github.com>
Co-authored-by: jinimukh <46768380+jinimukh@users.noreply.github.com>
Co-authored-by: Kunal Agarwal <kagarwal2@berkeley.edu>
Co-authored-by: Jared Zhao <jaredzhao@berkeley.edu>
Co-authored-by: Piyush Gupta <piyushg9794@gmail.com>
  • Loading branch information
11 people committed Dec 9, 2020
1 parent bb77423 commit 77a390d
Show file tree
Hide file tree
Showing 41 changed files with 665 additions and 326 deletions.
17 changes: 14 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,27 @@ lux/
- lux/
```

# Code Formatting
In order to keep our codebase clean and readible, we are using PEP8 guidelines. To help us maintain and check code style, we are using [black](https://github.com/psf/black). Simply run `black .` before commiting. Failure to do so may fail the tests run on Travis. This package should have been installed for you.

# Running the Test Suite

There is a suite of test files for ensuring that Lux is working correctly. These tests are triggered to run via [Travis CI](https://travis-ci.com/lux-org/lux) whenever there is a commit made to the lux repository.
There is a suite of test files for ensuring that Lux is working correctly. These tests are triggered to run via [Travis CI](https://travis-ci.com/lux-org/lux) whenever there is a commit made to the lux repository. You can run them locally to make sure that your changes are working and do not break any of the existing tests.

To run all the tests, including checking for code formatting, run:

```
make test
```

You can run them locally to make sure that your changes are working and do not break any of the existing tests:
To run a single test file, run:

```
python -m pytest tests/*.py
python -m pytest tests/<test_file_name>.py
```



# Code Formatting
In order to keep our codebase clean and readible, we are using PEP8 guidelines. To help us maintain and check code style, we are using [black](https://github.com/psf/black). Simply run `black --line-length 105 .` before commiting. Failure to do so may fail the tests run on Travis. This package should have been installed for you.

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
init:
pip install -r requirements.txt
test:
black --check .
python -m pytest tests/
.PHONY: init test
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
<a href='https://lux-api.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/lux-api/badge/?version=latest' alt='Documentation Status' align="center"/>
</a>
<a href='http://lux-project.slack.com/'>
<a href='https://lux-project.slack.com/join/shared_invite/zt-iwg84wfb-fBPaGTBBZfkb9arziy3W~g'>
<img src='https://img.shields.io/static/v1?label=chat&logo=slack&message=Slack&color=brightgreen' alt='Slack' align="center"/>
</a>
<a href='https://forms.gle/XKv3ejrshkCi3FJE6'>
<img src='https://img.shields.io/static/v1?label=email&message=signup&color=brightgreen' alt='Mailing List' align="center"/>
</a>
<a href='https://mybinder.org/v2/gh/lux-org/lux-binder/master'>
<img src='https://img.shields.io/badge/launch-binder-579ACA.svg?logo=data:image/png;base64,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' alt='Binder' align="center"/>
</a>
Expand Down Expand Up @@ -147,7 +150,8 @@ Lux is undergoing active development. If you are interested in using Lux, we wou

Other additional resources:

- Sign up for the early-user [mailing list](https://forms.gle/XKv3ejrshkCi3FJE6) to stay tuned for upcoming releases, updates, or user studies.
- Visit [ReadTheDoc](https://lux-api.readthedocs.io/en/latest/) for more detailed documentation.
- Clone [lux-binder](https://github.com/lux-org/lux-binder) to try out these [hands-on exercises](https://github.com/lux-org/lux-binder/tree/master/exercise) or a more comprehensive [tutorial series](https://github.com/lux-org/lux-binder/tree/master/tutorial) on how to use Lux.
- Join our [Slack channel](https://lux-project.slack.com/join/shared_invite/zt-iwg84wfb-fBPaGTBBZfkb9arziy3W~g) for support and discussion.
- Clone [lux-binder](https://github.com/lux-org/lux-binder) to try out these [hands-on exercises](https://github.com/lux-org/lux-binder/tree/master/exercise) or [tutorial series](https://github.com/lux-org/lux-binder/tree/master/tutorial) on how to use Lux.
- Join our community [Slack](https://lux-project.slack.com/join/shared_invite/zt-iwg84wfb-fBPaGTBBZfkb9arziy3W~g) to discuss and ask questions.
- Report any bugs, issues, or requests through [Github Issues](https://github.com/lux-org/lux/issues).
8 changes: 8 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ This website contains pages that overview of the basic and advanced functionalit

source/advanced/date
source/advanced/indexgroup
source/advanced/custom
source/advanced/architecture
source/advanced/interestingness
source/advanced/executor

.. toctree::
:maxdepth: 1
:caption: Reference

source/reference/config
source/reference/API


Indices and tables
==================
Expand Down
139 changes: 139 additions & 0 deletions doc/source/advanced/custom.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
***********************************
Registering Custom Recommendations
***********************************

.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/8-custom-action.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/8-custom-action.ipynb>`_]

In this tutorial, we will look at how you can register custom recommendation actions (i.e. tabs of recommendations) to display on the Lux widget. The custom actions can be globally defined and used across different dataframes. We look at the `Happy Planet Index <http://happyplanetindex.org/>`_ dataset, which contains metrics related to well-being for 140 countries around the world.

.. code-block:: python
df = pd.read_csv("https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/hpi.csv")
df["G10"] = df["Country"].isin(["Belgium","Canada","France","Germany","Italy","Japan","Netherlands","United Kingdom","Switzerland","Sweden","United States"])
lux.config.default_display = "lux"
df
As we can see, Lux displays several recommendation actions, such as Correlation and Distributions, which is globally registered by default.

Registering Custom Actions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Let's define a custom function to generate the recommendations on the dataframe. In this example, we register a custom action called `G10` to generate a collection of visualizations that showcases numerical measures that differs significantly across `G10 <https://en.wikipedia.org/wiki/Group_of_Ten_(economics)>`_ and non-G10 countries. In other words, we want to understand how the G10 and non-G10 countries differs based on the measures present in the dataframe.

Here, we first generate a VisList that looks at how various quantitative attributes breakdown between G10 and non-G10 countries. Then, we score and rank these visualization by calculating the percentage difference in means across G10 v.s. non-G10 countries.

.. code-block:: python
from lux.vis.VisList import VisList
intent = [lux.Clause("?",data_type="quantitative"),lux.Clause("G10")]
vlist = VisList(intent,df)
for vis in vlist:
# Percentage Change Between G10 v.s. non-G10 countries
a = vis.data.iloc[0,1]
b = vis.data.iloc[1,1]
vis.score = (b-a)/a
vlist = vlist.topK(15)
Let's define a custom function to generate the recommendations on the dataframe. In this example, we will use G10 to generate a VisList to calculate the percentage change of means Between G10 v.s. non-G10 countries.

.. code-block:: python
def G10_mean_difference(ldf):
# Define a VisList of quantitative distribution between G10 and non-G10 countries
intent = [lux.Clause("?",data_type="quantitative"),lux.Clause("G10")]
vlist = VisList(intent,df)
# Score each Vis based on the how different G10 and non-G10 bars are
for vis in vlist:
a = vis.data.iloc[0,1]
b = vis.data.iloc[1,1]
vis.score = (b-a)/a
vlist = vlist.topK(15)
return {"action":"G10", "description": "Percentage Change of Means Between G10 v.s. non-G10 countries", "collection": vlist}
In the code below, we define a display condition function to determine whether or not we want to generate recommendations for the custom action. In this example, we simply check if we are using the HPI dataset to generate recommendations for the custom action `G10`.

.. code-block:: python
def is_G10_hpi_dataset(df):
try:
return all(df.columns == ['HPIRank', 'Country', 'SubRegion', 'AverageLifeExpectancy',
'AverageWellBeing', 'HappyLifeYears', 'Footprint',
'InequalityOfOutcomes', 'InequalityAdjustedLifeExpectancy',
'InequalityAdjustedWellbeing', 'HappyPlanetIndex', 'GDPPerCapita',
'Population', 'G10'])
except:
return False
To register the `G10` action in Lux, we apply the `register_action` function, which takes a name and action as inputs, as well as a display condition and additional arguments as optional parameters.

.. code-block:: python
lux.register_action("G10", G10_mean_difference, is_G10_hpi_dataset)
After registering the action, the G10 recomendation action is automatically generated when we display the Lux dataframe again.

.. code-block:: python
df
.. image:: https://github.com/lux-org/lux-resources/blob/master/doc_img/custom-1.png?raw=true
:width: 700
:align: center
:alt: Displays default and user-defined actions as a VisList.

As expected, we see that G10 and non-G10 countries differs significantly in terms of their GDPPerCapita, but also in terms of their carbon footprint (Footprint) and number of expected happy year an average citizen can expect to live within a country (HappyLifeYears).

Since the registered action is globally defined, the G10 action is displayed whenever the display condition is satisfied (i.e. if the data schema matches that of the HPI dataset). For example, we might want to isolate the GDPPerCapita factor and only examine countries with high GDP. We can filter to only countries with GDPPerCapita over 40k and see the difference across the various quantitative attributes for these countries.

.. code-block:: python
df[df["GDPPerCapita"]>40000]
.. image:: https://github.com/lux-org/lux-resources/blob/master/doc_img/custom-1.png?raw=true
:width: 700
:align: center
:alt: Displays countries with GDPPerCapita > 40000 to compare G10 results.

As we can see, there is a less of a distinction between G10 and non-G10 countries across the measures when we only filter to only high GDP countries.

Navigating the Action Manager
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can inspect a list of actions that are currently registered in the Lux Action Manager. The following code displays both default and user-defined actions.

.. code-block:: python
lux.actions.__getactions__()
You can also get a single action attribute by calling this function with the action's name.

.. code-block:: python
lux.actions.__getattr__("G10")
.. image:: https://github.com/lux-org/lux-resources/blob/master/doc_img/custom-2.png?raw=true
:width: 700
:align: center
:alt: Retrieves a single attribute from Lux's action manager using its defined id.

Removing Custom Actions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Let's say that we are no longer in looking at the `G10` action, the `remove_action` function allows you to remove from Lux's action manager an action with its id. The action will no longer display with the Lux dataframe.

.. code-block:: python
lux.remove_action("G10")
After removing the action, when we print the dataframe again, the `G10` action is no longer displayed.

.. code-block:: python
df
.. image:: https://github.com/lux-org/lux-resources/blob/master/doc_img/custom-4.png?raw=true
:width: 700
:align: center
:alt: Demonstrates removing custom action from Lux Action Manager.
2 changes: 1 addition & 1 deletion doc/source/guide/FAQ.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ How do I set the Lux widgets to show up on default?
I want to change the opacity of my chart, add title, change chart font size, etc. How do I modify chart settings?
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
To add custom plot settings to the recommendations, you can set the :code:`plot_config` property of the dataframe. See `this tutorial <https://lux-api.readthedocs.io/en/latest/source/guide/style.html>`_ on how to configure chart properties. Lux currently only support chart modifications in Altair.
To add custom plot settings to the recommendations, you can set the global :code:`plot_config` property. See `this tutorial <https://lux-api.readthedocs.io/en/latest/source/guide/style.html>`_ on how to configure chart properties. Lux currently only support chart modifications in Altair.

How do I change aggregation functions, binning, or axis channels to non-default values?
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Expand Down
2 changes: 1 addition & 1 deletion doc/source/guide/export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Exporting Vis From Widget
********************************

.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/tutorial/3-widget-vis-export.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/3-widget-vis-export.ipynb>`_]
.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/3-widget-vis-export.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/3-widget-vis-export.ipynb>`_]

In this tutorial, we look at the `Happy Planet Index <http://happyplanetindex.org/>`_ dataset, which contains metrics related to well-being for 140 countries around the world. We demonstrate how you can select visualizations of interest and export them for further analysis.

Expand Down
2 changes: 1 addition & 1 deletion doc/source/guide/intent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Specifying Intent in Lux
********************************

.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/tutorial/1-specifying-intent.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/1-specifying-intent.ipynb>`_]
.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/1-specifying-intent.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/1-specifying-intent.ipynb>`_]

Lux provides a flexible language for communicating your analysis intent to the system, so that Lux can provide better and more relevant recommendations to you. In this tutorial, we will see different ways of specifying the intent, including the attributes and values that you are interested or not interested in, enumeration specifiers, as well as any constraints on the visualization encoding.

Expand Down
10 changes: 5 additions & 5 deletions doc/source/guide/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Styling Custom Plot Settings
********************************

.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/tutorial/4-chart-settings.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/4-chart-settings.ipynb>`_]
.. note:: You can follow along this tutorial in a Jupyter notebook. [`Github <https://github.com/lux-org/lux-binder/blob/master/tutorial/4-chart-settings.ipynb>`_] [`Binder <https://mybinder.org/v2/gh/lux-org/lux-binder/master?urlpath=tree/tutorial/4-chart-settings.ipynb>`_]

In the last tutorial, we saw how :code:`Vis` objects could be exported into visualization code for further editing. What if we want to change the chart settings for *all* the visualizations displayed in the widget. In Lux, we can change the chart settings and aesthetics by inputting custom plot settings the :code:`plot_config` property of the dataframe.
In the last tutorial, we saw how :code:`Vis` objects could be exported into visualization code for further editing. What if we want to change the chart settings for *all* the visualizations displayed in the widget. In Lux, we can change the chart settings and aesthetics by inputting global custom plot settings the :code:`plot_config`.

Example #1 : Changing Color and Title of all charts
---------------------------------------------------
Expand All @@ -31,11 +31,11 @@ Let's say that we want to change all the graphical marks of the charts to green
chart.title = "Custom Title" # add title to chart
return chart
We then set the plot configuration of the dataframe by changing the :code:`plot_config` property. With the added plot_config, Lux runs this user-defined function after every `Vis` is rendered to a chart, allow the user-defined function to override any existing default chart settings.
We then set the global plot configuration of the dataframe by changing the :code:`plot_config` property. With the added plot_config, Lux runs this user-defined function after every `Vis` is rendered to a chart, allow the user-defined function to override any existing default chart settings.

.. code-block:: python
df.plot_config = change_color_add_title
lux.config.plot_config = change_color_add_title
We now see that the displayed visualizations adopt these new imported settings.

Expand Down Expand Up @@ -108,7 +108,7 @@ We want to decrease the opacity of scatterplots, but keep the opacity for the ot
.. code-block:: python
df.plot_config = changeOpacityScatterOnly
lux.config.plot_config = changeOpacityScatterOnly
df
.. image:: ../img/style-6.png
Expand Down
Loading

0 comments on commit 77a390d

Please sign in to comment.