Live data from Hacker News

Vega-Altair: Declarative Visualization in Python

altair-viz.github.io

21–30 of 44 posts

Re: Vega-Altair: Declarative Visualization in Python

#21

Altair is great. I'm using Plotly more lately, for 2 reasons - chart have very good interactivity by default and I'm also a Dash user - so it comes in naturally. But I believe Altair is excellent for exploration - simple charts are very simple to create, and it's not complicated to create a complex exploration dashboard - with all charts linked between them - so you can select a subset of data on one chart, and it au…

Also Plotly generates Javascript so it has wrappers for many python frameworks such as Streamlit.

I'm also using it in a regular React app and it has quite decent APIs.

Re: Vega-Altair: Declarative Visualization in Python

#22
post #6
post #3

Are there non-declarative chart visualization libraries? I’ve always used matplotlib.pyplot [1] and while it doesn’t market itself as "declarative", I don’t see much difference: # Vega-Altair alt.Chart(source).mark_line().encode( x='x', y='f(x)' ) # Pyplot plt.plot(source) plt.xlabel('x') plt.ylabel('f(x)') [1]: https://matplotlib.org/stable/tutorials/pyplot.html

If we only look at the simplest example then I would agree that there is not much difference. But more complicated plots will require you to write code in a more verbose and imperative fashion when using matplotlib. Take a faceted plot like this scatter matrix [1] and try to plot it in matplotlib. You would need to set up the grid using subplots, then define the combinations you want and finally write logic to fill e…

Mirror, mirror on the wall, what’s the most declarative dataviz programming language of all? :-)

  *** SAS SCATTER MATRIX EXAMPLE ***
  proc sgscatter data=sashelp.cars;
  matrix Horsepower Acceleration Miles_per_Gallon / group=Origin;

  *** ALTAIR SCATTER MARIX EXAMPLE ***
  import altair as alt
  from vega_datasets import data

  source = data.cars()

  alt.Chart(source).mark_circle().encode(
    alt.X(alt.repeat("column"), type='quantitative'),
    alt.Y(alt.repeat("row"), type='quantitative'),
    color='Origin:N'
  ).properties(
    width=150,
    height=150
  ).repeat(
    row=['Horsepower', 'Acceleration', 'Miles_per_Gallon'],
    column=['Miles_per_Gallon', 'Acceleration', 'Horsepower']
  ).interactive()

Re: Vega-Altair: Declarative Visualization in Python

#24
I work as a data scientist (like many others in this thread) and Altair is a great tool for exploring the data. I really like the grammar of graphics approach and the ability to do things like cross-filter and the general ease of enabling interactivity are great! Amazing work by everyone on the Altair/Vega team.

There are some drawbacks though that have been holding some of my colleagues back from switching from e.g. Seaborn to Altair:

- No zoom by selecting the x- or y-range. Almost all other libraries implement box-zoom, Altair does not have this. This is probably the biggest complaint I have heard so far.

- Annotating data inside the plot is difficult. I don't mean `mark_text`, I mean placing an annotation that you would do in Matplotlib via `ax.text(...)`.

- Along side that: No TeX support.

- It does become slow once there is a large number of points in the chart (and you don't want to aggregate).

- Missing mapping features. I know you can have maps in the background of your plot, but I'm talking OSM like mapping.

- Working with layered + faceted charts takes some time to get used to.

- It used to be that if you had a dataframe with 100 columns and you were only plotting two of them, still all 100 columns would be saved to html. I think this is addressed in VegaFusion?

Still, I want to just emphasize how much I love Altair. To understand relations in your data, it's amazing to just assign color to a column, shape to another column and so on. Really neat! With a background in mathematics, it was also helping me to think about the whole tidy approach to dataframes, so that was an added benefit!

Re: Vega-Altair: Declarative Visualization in Python

#25
post #4

Is there a plotting library that uses webgl? I am only aware of Plotly that uses webgl for some of the graphs.

Bokeh has support for WebGL. We had to switch away from Vega/Altair when a project hit around 50,000 data points in a plot, but under ~5,000 data points Vega/Altair was still good.

Re: Vega-Altair: Declarative Visualization in Python

#27
We use Vega lite in our web sites. It gets us 90% where we want to be very quickly. The last 10% is a little fiddly.

It’s amazing though. High quality and downloadable graphs. We use it for single cell rna seq plotting and it’s pretty performant with large data sets (5000+ points on an xy scatter graph)

Re: Vega-Altair: Declarative Visualization in Python

#29

Working as a data scientist, I have exclusively used Altair since I joined my company in 2021. Every one of my coworkers uses Matplotlib. Two people said something like "Oh, you're using that library that's supposed to be better and probably is, but I just don't want to relearn everything for plotting" but nobody else has even shown interest, let alone taken the plunge. If you need to learn a plotting library and you…

I use seaborn to plot directly with pandas, does Altair have any extra advantages? Or is it a similar style?

Re: Vega-Altair: Declarative Visualization in Python

#30
post #9
post #3

Are there non-declarative chart visualization libraries? I’ve always used matplotlib.pyplot [1] and while it doesn’t market itself as "declarative", I don’t see much difference: # Vega-Altair alt.Chart(source).mark_line().encode( x='x', y='f(x)' ) # Pyplot plt.plot(source) plt.xlabel('x') plt.ylabel('f(x)') [1]: https://matplotlib.org/stable/tutorials/pyplot.html

I don’t know what you think declarative means, but the example you’re showing is as non-declarative as it could be for such a simple thing.

> I don’t know what you think declarative means, but the example you’re showing is as non-declarative as it could be for such a simple thing.

According to Wikipedia this is a style of programming where you describe _what_ you want rather than _how_ it should be done. What I see in my example is declarative per this definition: "I want a chart with , with this X label and that Y label".

Post reply on HN