-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Readme for Figure Factory Creation #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
aeac290
8eb60ea
19c1f96
68a539c
a4c472b
34f774d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Add Your Figure Factory to the Plotly [Python Library](https://plot.ly/python/) | ||
|
||
If you have ever wanted to contribute to the Plotly Python Library by adding a new chart type we don't have, now you have the resources to do so. This README will help you get started cloning the plotly.py repo, forking a new branch, creating a new figure factory, and pushing your results to the cloud to get feedback for merging. Just follow all these steps and you'll be ready to go. | ||
|
||
## Getting Started: | ||
1. Clone the `plotly.py` repo locally and then check out the master branch. | ||
|
||
``` | ||
$ git clone [email protected]:plotly/plotly.py.git | ||
$ git fetch origin | ||
$ git checkout master | ||
``` | ||
|
||
2. Checkout a new branch and give it an appropriate name. | ||
|
||
``` | ||
$ git checkout -b "my-new-ff" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "add-ff-type" |
||
``` | ||
|
||
## Create A figure_factory file | ||
1. Creating python file and updating `__init__.py` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should keep all the directions in the same tense so Create A figure_factory file
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could probably split this step into 2 steps: |
||
|
||
You are now ready to start writing your code. Begin by moving to the `plotly.figure_factory` directory in the `plotly.py` repo. Notice that there is an `__init__.py` file as well as a bunch of `_figure_factory_chart.py` files in this directory. Each type of unique plotly chart gets its own python file, and the name of each python file is found in the `__init__.py` file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm You are now ready to start writing your code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's not really true, not each type of unique plotly chart but rather each figure factory chart. I think this is important to distinguish so people don't think they can edit a non-figure factory chart type from this repo (and end up looking for the scatter python file for instance). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll clarify, thank you |
||
|
||
The inside of the `__init__.py` looks like: | ||
|
||
``` | ||
from __future__ import absolute_import | ||
|
||
# Require that numpy exists for figure_factory | ||
import numpy | ||
|
||
from plotly.figure_factory._2d_density import create_2d_density | ||
from plotly.figure_factory._annotated_heatmap import create_annotated_heatmap | ||
from plotly.figure_factory._candlestick import create_candlestick | ||
... | ||
``` | ||
|
||
If you want to make, for example, a chart called `foo`, then you must create a python file `_foo.py` and then add the following line to the end of `__init__.py`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes more sense for step 1 to be |
||
|
||
``` | ||
from plotly.figure_factory._foo import create_foo | ||
``` | ||
|
||
2. Imports | ||
|
||
In `_foo.py` write | ||
|
||
``` | ||
from __future__ import absolute_import | ||
``` | ||
|
||
at line 1. You can add other imports later if you will need them. | ||
|
||
3. The main function | ||
|
||
It's now time to write the main function `create_foo` that will be called directly by the user. It has the form: | ||
|
||
``` | ||
def create_foo(data, height=450, width=600, ...): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of using real attributes (as some people might think they have to add height and width) you could say |
||
""" | ||
Returns figure for a foo plot. | ||
|
||
:param (list) data: description of what 'data' is. | ||
:param (int) height: description of what 'height' is. | ||
:param (int) width: description of what 'width' is. | ||
# ... | ||
|
||
Example 1: | ||
''' | ||
|
||
''' | ||
|
||
Example 2: | ||
''' | ||
|
||
''' | ||
""" | ||
# code | ||
# ... | ||
# return fig | ||
``` | ||
|
||
You _must_ include what is known as a documentation string or doc string in your function, which is just a block string taht contains useful information about what the function does, the arguments of the function and their descriptions, and examples of this function in use. The doc string is displayed when the help method is run by a user: `help(create_foo)` or `create_foo?` in Jupyter. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must include a documentation string in your function. A doc string is a block string that contains useful information about what the function does, the arguments of the function and their descriptions, and examples of this function in use. The doc string is displayed when the help method is run by a user: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. *** ( |
||
|
||
The parameters are listed in the doc string with the format `:param (param_type) param_name: description.` Afterwards, you must include Examples which demonstrate the different capabilities and features of the function. For more information on proper doc string syntax see [PEP-257 page](https://www.python.org/dev/peps/pep-0257/). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to cap Examples |
||
|
||
After the doc string, you may write the main code of your function, which should result in returning the `fig`. Users will use your function in the following way: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the doc string, you will add the main code of your function, which should result in returning the |
||
|
||
``` | ||
# create figure | ||
fig = create_foo(...) | ||
|
||
# plot figure | ||
py.iplot(fig, filename='my_figure') | ||
``` | ||
|
||
The figure `fig` must be a Plotly Figure, meaning it must have the form `fig = graph_objs.Figure(data=data, layout=layout)`. | ||
|
||
4. Useful Tips | ||
|
||
It is often not a good idea to put all your code into your `create_foo()` function. It is best practice to not repeat yourself and this requires taking repeated blocks of code and puting them into a seperate function. Usually it is best to make all other functions besides `create_foo()` secret so a user cannot access them. This is done by placing a `_` before the name of the function, so `_aux_func()` for example. | ||
|
||
|
||
## Push to GitHub | ||
|
||
When you are finally finished your first draft of your figure factory, it is time to push it to the cloud and to get feedback from the Plotly team and other voluntary GitHub users. After you have added and commited all of your changes on the local branch, push the changes to a new remote branch on Git: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not 100% sure what:
means. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you have finished the first draft of your figure factory, it is time to create a pull request for the Plotly team to review. |
||
|
||
``` | ||
$ git push origin my-new-ff | ||
``` | ||
|
||
Thank you for reading and thanks for contributing to Plotly's Graphing Library! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may want to link the general plotly.py contribution instructions as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say: Add a Figure Factory to...