Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Graphotti

image}

This is a library for creating plots in python that is guided by the following principles:

  • Simple, intuitive, and consistent api
    • Creating plots should be easy and fun.
    • The API should be simple, but also allow basic customization of things like the x & y axes, and grids.
    • It should be easy for you to explore your data without being bogged down by syntax and boilerplate code.
  • Easy Plot Mashability.
    • Often times you have several separate plots that you want to combine into a single plot, eg overlaying them, or stacking them on top of each other, or next to each other. But doing so can be a hassle.
    • But it shouldn't be a hassle. It should be as easy as doing simple arithmetic to combine them.
    • It should be as easy as a+b+c, literally.
    • With Graphotti, arithmetic operations actually have semantic meaning for the plots.
    • Eg given plots a, b and c, the operation a+b+c overlays the plots on top of each other.
    • Other math operators will also have meaning and allow you to stack plots on top of each other, or side by side, or as a grid.
  • Plotting Library Agnostic
    • Different plotting libraries have their advantages and disadvantages in terms of the way they display the plot.
    • Your project might require rendering the same plot to different plotting libraries, for different purposes (eg, during exploration, production, or for publication).
    • But you should not have to write completely new code from scratch to plot the exact same plot, or deal with the peculiarities of each library (and spending hours on stackoverflow).
    • With Graphotti, you can render the plot using different engines by simply setting a single parameter.
    • eg given a Graphotti plot object p, we can render it using matplotlib or plotly as follows:
      • p.plot() to display using the default engine (matplotlib)
      • p.plot("mpl") to display using matplotlib
      • p.plot("ply") to display using plotly
  • Intuition Building
    • It should be quick and easy to plot functions such as sin or cos or any other math functions easily, in order to get an intuition of what they do. Ideally it should be done by just writing a math formula in text, without having to manually create your own x and y arrays using math libraries.
    • eg: funcplot("exp(x)/(1+exp(x))")
    • NOTE: this feature is not implemented yet.

Read the white paper for more information about the ambitions of this project.

Installing and Setting up

pip install -e git+https://github.com/ronrest/graphotti.git#egg=graphotti
importgraphottiasgh

You can also import the following depending on whether you want to render the plots using matplotlib, or plotly.

# For rendering using plotly engine within a jupyter notebookfromplotly.offlineimportinit_notebook_modeinit_notebook_mode(connected=True)
# For rendering using matplotlib engine within a jupyter notebook%matplotlibinline

Simple Introduction for creating plots

Creating a lineplot is as simple as:

a=gh.line([7,8,9,8,6])
a.plot()

image}

Combining Plots using Plot Arithmetic

Overlaying plots

You can use the + and - operators to overlay plots on top of each other.

  • + makes the plots share the same y axis
  • - makes the plots on the right hand side of the operator use its own independent y axis

In the following example, three plots are created, overlayed on top of each other, and all sharing the same y axis.

fromplotimportlineplota=gh.line([7,8,9,8,6])
b=gh.line([2,1,3,2])
c=gh.line([11,15,10,9,5])
overlay=a+b+coverlay.plot()

image

In the following example, the three plots are overlayed but the final plot uses its own independent y axis.

overlay=a+b-coverlay.plot()

image

You can also overlay plots of different types, eg, below we overlay a lineplot, a step plot, and a scatterplot all on top of each other.

s=gh.step(x= [1,4,5,6,7,9], y=[0,1,0,1,2,0], name="step plot")
l=gh.line(x= [0,3,6,7,8,9], y=[1,2,4,1,2,4], name="line plot")
c=gh.scatter([3,8,2,6,2,4], [4,3,3,2,1,6], labels=["a","b","c","d","e","f"], name="scatter plot")
overlayed= (l+s+c)
overlayed.plot(title="Multiple plot types overlayed")

image}

Slicing Plots

Just like you can slice lists, and arrays to get a subset of the data, you can take a slice of a plot object to get a segment of the plot. This is useful if you want to zoom in and focus on a small region of the plot.

EXAMPLE:

a=gh.line([5,7,8,8,7,5,2,5,6,5,4,2,3])
b=gh.line([2,1,3,2,4,5,4,2,3,2,3,1,1,2,0])
c=gh.line([4,6,5,3,6,5,7,4,5,3,5,2,1,3,4])
overlay=a+b+c# Unsliced plotoverlay.plot()

image}

# Sliced plotoverlay[6:10].plot()

image

TODO: Add example of slicing datetime indexed plots

Y scales

NOTE: only implemented on the plotly engine so far. Not implemented on the matplotlib engine yet.

You can set eg a plot to be in log scale by setting the scaley property.

a=gh.line([1,10,20,30,40,50,60,70,80], scaley="linear")
b=gh.line([10,20,30,40,50,60,70,80, 90], scaley="log")
# plot shown in log scaleb.plot()
# When sharing a y axis, the settings of the first plot takes precedence,# so both show as linear
(a+b).plot()
# Here both are shown as log scale
(b+a).plot()
# If not sharing a y axis, then each plot is shown in their corresponding# y scale setting
(a-b).plot()

Saving To File

Save plots by passing a file path string to the file argument when calling plot().

overlay.plot(file="myplot.jpg")

Plotting columns of a Pandas dataframe

# Line plot of all the columns of a dataframe, sharing same y axesp=gh.dfplot(df, kind="line")
# Step plot of all the columns of a dataframe, with independent y axesp=gh.dfplot(df, kind="step", sharey=False)

Chosing Rendering Engines

Setting default rendering engine

By default, the rendering engine used is Matplotlib. But you can change the default as follows.

# Set default rendering engine to be Matplotlibgh.set_default_engine("mpl")
# Set default rendering engine to be Plotlygh.set_default_engine("ply")

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

Setting rendering engine for specific figure

You can override the default rendering engine and set a different one for individual plots. The first positional argument to the plot() function allows you to select which rendering engine to use to render the plot.

Possible values are:

  • "mpl" Use Matplotlib
  • "plotly" or "ply" Use plotly

EXAMPLES:

# Plot using matplotlib explicitlyoverlay.plot("mpl")
# Save as an image using matplotlib explicitlyoverlay.plot("mpl", file="myplot.jpg")
# Plot using Plotlyoverlay.plot("ply")
# Save as an interactive HTML plot using Plotlyoverlay.plot("ply", file="myplot.html")

Contributing

See the contributing.md file for details on how to contribute to this project.

About

A library for creating plots that can easily be combined and rendered on different plotting libraries

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages