question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty plot when using DataFrame as Chart object

See original GitHub issue

Chart() seems to get a url to dataframe but not a DataFrame object as described in the guide. But this is not handy as, while doing analysis, you usually load data on top, go through some stats and calcualtions and than visulize them. Basically, you cannot use the DataFrame object created with pd.read_csv into Chart(). See example below:

` stocks = pd.read_csv(‘C:\Program Files\Python\Python36-32\lib\site-packages\vega_datasets\data\stocks.csv’)

type(stocks)

stocks.tail()

stocks.groupby([‘symbol’]).agg({‘price’: ‘mean’})

alt.Chart(data=stocks).mark_line().encode( x=‘date:T’, y=‘price:Q’, color=“symbol:N”, column=“symbol:N”) `

csv_pandas

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Apr 18, 2018

OK, if that’s the output of to_dict() on your chart, then it looks like you’re not passing the dataframe to as chart data, but rather passing a string containing the local CSV file path to the chart. That local filepath is not a valid URL, which is why you’re not getting any output.

If you want to pass data using a string referencing a local filepath, you should use a URL starting with file://; e.g. alt.Chart(data="file://C:/Program Files/Python/Python36-32/lib/site-packages/vega_datasets/data/stocks.csv")

But since you said above that you were trying to pass the dataframe itself as data, I suspect that you somewhere mixed up your variable names. Make certain that what you are passing to the chart is actually what you think it is; passing a dataframe should work correctly whether it’s loaded from the web or from a local file.

0reactions
jakevdpcommented, Mar 6, 2020

The fig.to_dict() line is not doing anything here; it can be removed (it returns a dictionary representation of the chart without modifying the state of the chart).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plots coming out empty with pandas.plot - Stack Overflow
I can get the plot to work using only one axis, but when I use two it comes out empty. I've tried separating...
Read more >
Chart visualization — pandas 1.5.2 documentation - PyData |
You can also create these other plots using the methods DataFrame.plot. ... after plotting by calling ax.set_aspect('equal') on the returned axes object.
Read more >
Plotting Visualizations Out of Pandas DataFrames
Initializing the Plots Object. Plotting can be performed in pandas by using the “.plot()” function. ... For now, create an empty dataframe.
Read more >
Create Pandas Plot Bar Explained with Examples
Python Pandas DataFrame.plot.bar() is used to plot the graph ... a clear look for the ability to compare the length of the objects....
Read more >
Plot With Pandas: Python Data Visualization for Beginners
You can use both pyplot.plot() and df.plot() to produce the same graph from columns of a DataFrame object. However, if you already have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found