Git Product home page Git Product logo

plost's Introduction

๐Ÿ… Plost

A deceptively simple plotting library for Streamlit.

Because you've been writing plots wrong all this time.

๐Ÿ‘‡ THE REAL README IS ACTUALLY HERE:

Open in Streamlit

๐Ÿ‘† You can find interactive examples, documentation, and much more in the app above.

Our goal

  • What you need 99% of the time is insanely easy
  • The other 1% is impossible. Use Vega-Lite instead!

Getting started

pip install plost

Basics

Plost makes it easy to build common plots using the Vega-Lite library but without having to delve into Vega-Lite specs (unless you're doing something tricky), and without having to melt your DataFrame from long format to wide format (the bane of most Vega-Lite plots!)

For example, let's say you have a "long-format" table like this:

time stock_name stock_value
... stock1 1
... stock2 2
... stock1 100
... stock2 200

Then you can draw a line chart by simply calling line_chart() with some column names:

import plost

plost.line_chart(
  my_dataframe,
  x='time',  # The name of the column to use for the x axis.
  y='stock_value',  # The name of the column to use for the data itself.
  color='stock_name', # The name of the column to use for the line colors.
)

Simple enough! But what if you instead have a "wide-format" table like this, which is super common in reality:

time stock1 stock2
... 1 100
... 2 200

Normally you'd have to melt() the table with Pandas first or create a complex Vega-Lite layered plot. But with Plost, you can just specify what you're trying to accomplish and it will melt the data internally for you:

import plost

plost.line_chart(
  my_dataframe,
  x='time',
  y=('stock1', 'stock2'),  # ๐Ÿ‘ˆ This is magic!
)

Ok, now let's add a mini-map to make panning/zooming even easier:

import plost

plost.line_chart(
  my_dataframe,
  x='time',
  y=('stock1', 'stock2'),
  pan_zoom='minimap',  # ๐Ÿ‘ˆ This is magic!
)

But we're just scratching the surface. Basically the idea is that Plost allows you to make beautiful Vega-Lite-driven charts for your most common needs, without having to learn about the powerful yet complex language behind Vega-Lite.

Check out the the sample app / docs for a taste of other amazing things you can do!

Juicy examples

Check out the documentation app!

Documentation

This is in the documentation app too!

plost's People

Contributors

snehankekre avatar tvst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

plost's Issues

Bug Report Bar Chart

Jo @tvst ,

think i found a bug.
What i tried is:

plost.bar_chart(
    data=datasets['stocks'],
    bar='company',
    value=['q2', 'q3'],
    direction='horizontal'
)

But values of q3 get stacked on top of q2 even though the
values of q3 should be plotted as part of q2 as the value of q2 is higher.
For vertical it works as expected.

Could you double check and in case fix that?

Best regards
Chris

Feature request

Hi @tvst ,

could you please add an easier way to pass individual color values?
Why I am asking is, i have bar_chart and i want to add a color for each value in the bar chart:

plost.bar_chart(
data=df, 
bar="epic", 
value=["time_1", "time_2", "time_3"],
direction="horizontal", 
colors=["#0001","#0002","#0003"]
)

So each bar has the three times in a different color for all unquie values in epic.
Also i saw you used the param legend=None but never passed any value, how could i use it to specifiy the x-axis value?

Best Regards
Chris

color attribute not supported

In the current version of plost 0.2.5, color attribute of every chart type is not supported.

Looking in the code, there seem to be a lack of passing through the value of the color argument.

One easy fix is to replace every

spec = D(
        mark=D(type='circle', tooltip=True),
        encoding=D(
            x=_clean_encoding(data, x),
            y=y_enc,
            color=color_enc,
            size=_clean_encoding(data, size, legend=legend),
            opacity=_clean_encoding(data, opacity, legend=legend),
        ),
        selection=_get_selection(pan_zoom),
    )

by

spec = D(
        mark=D(type='circle', tooltip=True),
        encoding=D(
            x=_clean_encoding(data, x),
            y=y_enc,
            color=_clean_encoding(data, color),
            size=_clean_encoding(data, size, legend=legend),
            opacity=_clean_encoding(data, opacity, legend=legend),
        ),
        selection=_get_selection(pan_zoom),
    )

The change is in the line color=color_enc to color=_clean_encoding(data, color).

how tricky is it to implement two-way communication between plots and python?

Thank you for this great library ๐Ÿ‘ !
I'm wondering how difficult it is to add two-way communication between chart objects and streamlit in order to update streamlit applications based upon click events, selections, etc... on charts. From some preliminary digging it seems like it's pretty non-trivial but want to be sure I'm not missing something obvious.
I am interested in working on this but it would be great to get some understanding of the level of challenge first.

Line Chart with Dots

Hi @tvst ,

can i somehow add dots to the linechart?
Plus, can i ushed dashed lines?

Best regards
Chris

Certain legends are black-on-dark in dark mode

Hi, not a user, just a passerby, but I noticed that on dark mode of the demo site some of the legends/labels are black (whereas some are, correctly, white).

For example, the q2 and q3 in the below screenshot (whereas the individual bar legends are correct).

image

Why do I need to explictly assign bar/value/x/y args for every plost funcs

I'm trying to plot a chart via plost instead of streamlit, this code is fine:
st.bar_chart(df)
it uses index as bar index, each columns as values, however this code raises an error:
plost.bar_chart(df)
TypeError: bar_chart() missing 2 required positional arguments: 'bar' and 'value'
I need to change the code like this:
plost.bar_chart(df.reset_index(names=['index']),bar='index',value=list(df.columns))
It is weird and no need to copy and change the df object at the first place, why do I need to explictly assign bar/value/x/y args for every plost funcs, why don't you just use the index and whole columns as value content to run the render as default?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.