text stringlengths 1 93.6k |
|---|
|------|------------|-------------|
|
| ... | stock1 | 1 |
|
| ... | stock2 | 2 |
|
| ... | stock1 | 100 |
|
| ... | stock2 | 200 |
|
Then you can draw a line chart by simply calling `line_chart()` with some
|
column names:
|
```python
|
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:
|
```python
|
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:
|
```python
|
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.
|
"""
|
@st.cache
|
def get_datasets():
|
N = 50
|
rand = pd.DataFrame()
|
rand['a'] = np.arange(N)
|
rand['b'] = np.random.rand(N)
|
rand['c'] = np.random.rand(N)
|
N = 500
|
events = pd.DataFrame()
|
events['time_delta_s'] = np.random.randn(N)
|
events['servers'] = np.random.choice(['server 1', 'server 2', 'server 3'], N)
|
N = 500
|
randn = pd.DataFrame(
|
np.random.randn(N, 4),
|
columns=['a', 'b', 'c', 'd'],
|
)
|
stocks = pd.DataFrame(dict(
|
company=['goog', 'fb', 'ms', 'amazon'],
|
q2=[4, 6, 8, 2],
|
q3=[2, 5, 2, 6],
|
))
|
N = 200
|
pageviews = pd.DataFrame()
|
pageviews['pagenum'] = [f'page-{i:03d}' for i in range(N)]
|
pageviews['pageviews'] = np.random.randint(0, 1000, N)
|
return dict(
|
rand=rand,
|
randn=randn,
|
events=events,
|
pageviews=pageviews,
|
stocks=stocks,
|
seattle_weather=pd.read_csv('./data/seattle-weather.csv', parse_dates=['date']),
|
sp500=pd.read_csv('./data/sp500.csv', parse_dates=['date']),
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.