I have a dataset and I plotted using plotly python
The name of the models is shown as a legend on the right side which makes it a little difficult to interpret. Is there any way to write the model name just above the color circle represent on the graph similar to what shown below? Something similar in mathplotlib will also help me.
You need to add labels in you scatter statement.
import plotly.express as px
#df data
fig = px.scatter(df, x="latency", y="AP", text="type", size_max=60)
fig.update_traces(textposition='top center')
Related
I'm trying to change the style of sns PairGrid graph. Namely, I want to add a frame around each of the grid graphs. What one graph looks like right now:
How I want it to look:
I've already spent a ton of time reading the documentation and searching the Internet, but I haven't found any suitable answer. Is it even possible with PairGrid?
Thank you all for your help.
Use the despine=False option of PairGrid:
import seaborn as sns
penguins = sns.load_dataset("penguins")
g = sns.PairGrid(penguins, despine=False)
g.map(sns.scatterplot)
Example:
I am facing a problem with the Scatter3d from plotly: the figure is always truncated at the bottom:
I create the plot via plotly.express this way:
fig = px.scatter_3d(BFM_pcaFull, x=0, y=1, z=2, color=3)
with BFM_pcaFull being the pandas.DataFrame where the data are stored. I tried to create the plot via plotly.graph_object instead of plotly.epxress but the result is the same.
I tried to tweak the layout parameter via the update_layout() method of fig:
Padding
Auto margin
Scaling
scaleratio
constrain
of course without any change to the graph (which does surprise me and make me think I am doing something wrong, even if apparently the 3D surface seems to follow different rules somewhat).
An issue for the same problem is open on the Github repo of the project but has not been solved so far (https://github.com/plotly/plotly.py/issues/3785).
Has anybody faced the same problem and found a solution by any chance?
Thanks for your help
To avoid missing parts of the graph in a 3D graph, you can change the viewpoint angle. See here for more information. The following code can be used to deal with this problem.
import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length',
y='sepal_width', z='petal_width',
color='species')
fig.show()
When the camera viewpoint is changed
fig.update_layout(margin=dict(l=0,r=0,t=0,b=0), scene_camera=dict(eye=dict(x=2.0, y=2.0, z=0.75)))
I am using the below script for plotting the chart using python:
ax = matplotlib.pyplot.scatter(dataset.x,dataset.y,s=dataset.Colorcode*30,c=pandas.Categorical(dataset.y).codes,cmap=matplotlib.pyplot.cm.Spectral)
for line in range(0,dataset.shape[0]):
matplotlib.pyplot.text(dataset.x[line],dataset.y[line],dataset.Colorcode[line],horizontalalignment='center',size='small',weight='semibold')
matplotlib.pyplot.grid()
matplotlib.pyplot.show()
A chart is plotted as below:
As you can see it's with multiple colors and I only want to plot with three colors as below:
Can you please guide me on how I can achieve this? I am new to python.
I'm relatively new to python and this is the first project that I'm working on. I'm trying to plot a simple multi line chart using altair onto a folium marker's popup. I followed the examples on this page https://github.com/python-visualization/folium/blob/master/examples/Popups.ipynb. But when I click on the marker, it's just plain white. The map and markers are plotted fine except the popup.
This is what my whole dataset looks like :
Here is the code:
import pandas as pd
import folium
import altair as alt
import json
chart = alt.Chart(df).mark_line().encode(
x='index',
y='Ambala',
color='Variable')
chart_2 = json.loads(chart.to_json())
m = folium.Map([30,-80],zoom_start=2)
popup = folium.Popup(max_width=650)
folium.Vega(chart_2, height=350, width=650).add_to(popup)
folium.Marker([30, -80], popup=popup).add_to(m)
m
Note that this just a sample of code. I'll be implementing this on a larger scale in my project.
I tried to plot a visualization (which I found here : https://github.com/python-visualization/folium/blob/master/examples/data/vis1.json) and this seemed to work fine. I just don't understand why the same code works for their plot but not for mine even though altair produces a fine looking chart from my code. Sorry if this is sounds silly, I'm still a beginner and python is my first language. Thanks
If you want to use an Altair chart inside a folium map, you need to use a VegaLite object instead of a Vega object. You just need to change the line with the Vega object like that : folium.features.VegaLite(chart_2, height=350, width=650).add_to(popup)
I understand that it is possible to export a Plotly graph, and that I can display it.
While sharing notebooks, the matplotlib plots remain intact in the Jupyter Notebooks, however, the Plotly graphs do not. They simply disappear
I understand that the Plotly graph is browser rendered, but is there any way I can store the graph in the ipynb file when I export it?
Is there any way that I can display the Plotly graph, just like the matplotlib graph?
Edit: As suggested in an answer, I tried to save it to a figure object, and display that, but no luck there either :/
If you put the code for a series of graphs in a single cell, execute it and save it, I think it will be displayed the next time you open it.
import plotly.express as px
df = px.data.iris() # iris is a pandas DataFrame
fig = px.scatter(df, x="sepal_width", y="sepal_length")
fig.show()