I wanna to draw scatter plot by altair to my dataframe.
In my dataframe (=df) if df[‘a’] = b, I draw circle point and if df[‘a’] = c, I draw triangle point.
I divided dataframe into column [‘a’] = b and column [‘a’] = c and drew two altairs. but I really want to make simple code.
So please tell me to one altair contains two shape (circle, triangle).
This is my code.
df_b = df[df[‘a’] == ‘b’]
df_c = df[df[‘a’] == ‘c’]
b = alt.Chart(df_b).mark_circle(size=50).encode(
x=alt.X(‘y:Q’, axis=None),
y=alt.X(‘x:Q’, axis=None)
)
c = alt.Chart(df_c).mark_point(shape=‘triangle’, filled=True, size=70).encode(
x=alt.X(‘y:Q’, axis=None),
y=alt.X(‘x:Q’, axis=None)
)
You can achieve this by first adjusting your DataFrame structure so that you combine df_b and df_c into the same DataFrame. Now, you’ll have column a as in df[‘a’] that has values of ’b’ and ’c’ as in your example code snippet.
Next, in your altair code, make sure to add the color parameter and for this define column a as the column that it reads data from. For example this would be something like the following:
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.