Empty plot when using DataFrame as Chart object
See original GitHub issueChart() 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”) `
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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).