Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

altair.utils.schemapi.SchemaValidationError: VConcatChart has no parameter named 'selection' #61

Closed
Philliec459 opened this issue Nov 27, 2023 · 6 comments

Comments

@Philliec459
Copy link

Hello,

I have been using Altair for a few years, but now having trouble launching the altair_viewer where I am getting the following error message:

altair.utils.schemapi.SchemaValidationError: VConcatChart has no parameter named 'selection'

My code is shown below. It is on the newer installations of Altair where I have a problem, so I am guessing my code is out of date.

`#from pandas import DataFrame, read_csv
from pandas import DataFrame

import altair as alt
import altair_viewer

#alt.renderers.enable('altair_viewer')
import altair_transform
alt.data_transformers.disable_max_rows()

import pandas as pd
import numpy as np

import geolog

Load data from geolog

while geolog.gettable():

df=pd.DataFrame({'wells':wells,'date':date,'bopm':bopm,'bwpm':bwpm,'xx_bottom':xx_bottom,'yy_bottom':yy_bottom,'wor':wor,'wcut':wcut,'lwcut':lwcut,'lwor':lwor})

interval = alt.selection_interval()

base = alt.Chart(df).properties(
    width=1000,
    height=1000, 
).add_params(interval)


points = base.mark_point(filled=True).encode(
    x='xx_bottom:Q',
    y='yy_bottom:Q',
    size='bopm:Q',
    #color=alt.condition(interval, 'wells', alt.value('lightgray')),
    color=alt.condition(interval, 'wells', alt.value('lightgray')),
    tooltip='wells', 
).properties(
    title='Field Map, Wells Sized by BOPM',
    selection=interval
)


timeseries = base.mark_line(clip=False).encode(
    x='date:T',
    #alt.X('date:T', timeUnit='year', axis=alt.Axis(title='')),
    y='sum(bopm):Q',
    #y=alt.Y('sum(bopm):Q', scale=alt.Scale(domain=(0, 10000000000))),
    #color=alt.Color('wells:O')
    color=alt.value('green'),
    tooltip='date:T' 
).properties(
    title='Production by Well in BOPM',
    width=450,
    height=300,
    #selection=interval
).transform_filter(
    #title='Volve Field BOPD',    
    interval
)


timeseries2 = base.mark_line(clip=False).encode(
    x='date:T',
    #alt.X('date:T', timeUnit='year', axis=alt.Axis(title='')),
    y='sum(bwpm):Q',
    #y=alt.Y('sum(bwpm):Q', scale=alt.Scale(domain=(0, 10000000000))),
    #color=alt.Color('wells:O')
    color=alt.value('blue'),
    tooltip='date:T', 
).properties(
    title='Production by Well in BWPM',
    width=450,
    height=300,
    #selection=interval
).transform_filter(
    #title='Volve Field BOPD',    
    interval
)


histd = alt.Chart(df).mark_line().encode(
    x='date:T',
    #alt.X('date:T', timeUnit='year', axis=alt.Axis(title='')),
    y='median(lwcut):Q',
    #alt.Y('mean(wcut)', scale=alt.Scale(type='log', base=10, domain=(0.001, 1.0)), axis=alt.Axis(orient='left') ),
    color=alt.value('blue'),
    #color='wells'
    #tooltip='date:T', 
).properties(
    width=1000,
    height=300
).transform_filter(
    interval
)

histcum = alt.Chart(df).mark_line().encode(
    x='bopm:Q',
    #alt.X('date:T', timeUnit='year', axis=alt.Axis(title='')),
    y='median(lwcut):Q',
    #alt.Y('mean(wcut)', scale=alt.Scale(type='log', base=10, domain=(0.001, 1.0)), axis=alt.Axis(orient='left') ),
    color=alt.value('blue'),
    #color='wells'
    #tooltip='date:T', 
).properties(
    width=1000,
    height=300
).transform_filter(
    interval
)

histcum2 = alt.Chart(df).mark_line().encode(
    #x='bopm:Q',
    alt.X('bopm:Q',  axis=alt.Axis(title='')),
    #y='median(lwcut):Q',
    alt.Y('mean(wcut)', scale=alt.Scale(type='log', base=10, domain=(0.00001, 1.0)), axis=alt.Axis(orient='left') ),
    color=alt.value('blue'),
    #color='wells'
    #tooltip='date:T', 
).properties(
    width=1000,
    height=300
).transform_filter(
    interval
)



first = points 
second = timeseries | timeseries2 
third =  histd 
forth = histcum

#points & timeseries & timeseries2 & bhp & hist & hist2 & hist3 

plot=first & second & third & forth

#plot.show()

altair_viewer.show(plot)

# Store data into geolog
geolog.puttable()

`

@Philliec459
Copy link
Author

I think that I am past the VConcatChart has no parameter named 'selection' and now I have a new error:

altair_viewer._utils.NoMatchingVersions: No matches for version='5.15.1' among ['4.0.2', '4.8.1', '4.17.0'].

I have had Altair working great until just recently updating python. Now Altair is giving me fits.

@joelostblom
Copy link
Member

Altair viewer is not supported in Altair 5+. Depending on what functionality you rely on from it, there might be another solution, can you say more about what you use altair viewer for?

@Philliec459
Copy link
Author

That might explain it that Altair viewer is no longer an option.

I have been using Altair for years, but now all of my old python code with Altair no longer work. I have discovered a few changes I need to make:

  • Instead of add_selection(interval) we now use add_params(interval)
  • We no longer use selection=interval in properties

For my jupyter notebooks I just use a line that mentions what I want to plot.
`plot=first & second & third & forth

plot
`
However, for a non notebook env I have always used:

`alt.renderers.enable('altair_viewer')

plot.show()`

This no longer works.

I have tried to launch the interactive browser using commands like:

#plot.show() altair_viewer.display(plot) #altair_viewer.show(plot)

altair_logdata

@Philliec459
Copy link
Author

Altair 5 is automatically installed with my conda env so I removed and reinstalled altair using conda install altair=4 and now I am back to normal in a non-Jupyter Notebook/Lab environment.

I am not sure how you are supposed to use Altair 5 without a viewer, but I am sure I am missing something here. Anyway Altair 4.2 works great for my needs.

@joelostblom
Copy link
Member

joelostblom commented Dec 4, 2023

Yes, to open charts from a terminal in altair 5, there is currently no as convenient way as using altair_viewer in altair <5. Most IDEs such as JupyterLab, VS Code etc should work fine, but for a terminal you would currently need to save the file and then open it in a browser. Something like this:

import altair as alt
import webbrowser
import os

filename = 'chart.html'
alt.Chart().mark_circle().save(filename)
webbrowser.open('file://' + os.path.realpath(filename))

You could put that in a function so that it's only a single line of code. Maybe we should put something similar in altair itself, but it would of course be nice to have a more robust option like altair_viewer in altair 5 as well (although I'm not sure the details of what altair_viewer adds over something simple like this).

@joelostblom
Copy link
Member

Since Altair 5.3, the functionality of Altair Viewer is now available in Altair via the vl-convert package instead. See the docs on how to use the browser renderer to display charts via .show(), and the PR vega/altair#3379 for more details.

We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for rendering charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants