Turn data-labels in Plotly Polar Plot - python

Hi i have a dataset i am displaying in Plotly Polar.
However all the datalabels are horizontal, so they overlap each other and make it hard to read the plot.
Is there a way to have the data-labels turned so they are radially distributed?
df=file_from_xlsx
fig = px.scatter_polar(df, r="data", theta="Group", text="individual_data_label")
How can i turn the data labels, so they are in line with the theta angle already defined for the data points?
Thanks for your help!

Related

Random (false data) lines appearing in contourf plot at certain # of levels

I'm trying to use matplotlib and contourf to generate some filled (polar) contour plots of velocity data. I have some data (MeanVel_Z_Run16_np) I am plotting on theta (Th_Run16) and r (R_Run16), as shown here:
fig,ax = plt.subplots(subplot_kw={'projection':'polar'})
levels = np.linspace(-2.5,4,15)
cplot = ax.contourf(Th_Run16,R_Run16,MeanVel_Z_Run16_np,levels,cmap='plasma')
ax.set_rmax(80)
ax.set_rticks([15,30,45,60])
rlabels = ax.get_ymajorticklabels()
for label in rlabels:
label.set_color('#E6E6FA')
cbar = plt.colorbar(cplot,pad=0.1,ticks=[0,3,6,9,12,15])
cbar.set_label(r'$V_{Z}$ [m/s]')
plt.show()
This generates the following plot:
Velocity plot with 15 levels:
Which looks great (and accurate), outside of that random straight orange line roughly between 90deg and 180deg. I know that this is not real data because I plotted this in MATLAB and it did not appear there. Furthermore, I have realized it appears to relate to the number of contour levels I use. For example, if I bump this code up to 30 levels instead of 15, the result changes significantly, with odd triangular regions of uniform value:
Velocity plot with 30 levels:
Does anyone know what might be going on here? How can I get contourf to just plot my data without these strange misrepresentations? I would like to use 15 contour levels at least. Thank you.

python pandas 3D voxel plot

I'm trying to use matplotlib to generate a 3D voxel plot of my spatial data to visualise where players go in my game.
This is the cube dataframe that I'm generating using the bounds of the game and placing a cube at regular intervals along each dimesion, with xyz describing the centre of each voxel and the offsets describing the bounds of each voxel. The value refers to the number of times a player entered that voxel so I can generate the heat map.
I'm currently using a scatter graph and that is working very well, but I want to be able to convert what I currently have into a voxel graph.
fig = matplotlib.pyplot.figure(figsize=(12, 12))
ax = fig.add_subplot(projection='3d')
print("Plotting")
ax.scatter(cubeDF['x'], cubeDF['y'], cubeDF['z'], c=cubeDF['value'], )
fig.show()
I'm sorry if this question is rushed but it's for my final year project and it's due in soon so I'm very stressed out about this whole thing

How to make scatter plot in spherical coordinates theta, phi, r (w/ or w/o plotly)?

my question refers mostly to plotly, but plotting alternatives with other packages are welcome!
I have successfully made a light cone plot (kind of a wedge plot) in polar coordinates with this code:
import plotly.express as px
fig = px.scatter_polar(df_rdwz, r='z', theta='ra',
range_theta=[-6,6], range_r=[0.8,3.2], start_angle=0, direction="counterclockwise")
fig.show()
The result looks like this:
But I have as data also a phi angle for the depth. I would like to use it to make this plot 3d. Is there something like px.scatter_spherical or px.scatter_3d_spherical that would allow me this? Alternatively, I know I can use go.Scatter3d with cartesian coordinates (x,y,z) - can I plot the dots in cartesian coordinates and afterwards just make the AXIS of go.Scatter3d to be drawn spherically (theta, phi, r)?
Any other suggestions of how to make this plot in 3d with spherical axis labels are welcome! tnx

Highlighting Outliers in scatter plot

I am using dataset "tips".
Plotting scatter plot with below code
sns.scatterplot(data=df['total_bill'])
I want to show the outliers let's say in this case points which are above 40 on y-axis, in different color or big or is it possible to draw a horizontal like at 40?
With below code desired result achieved.
sns.scatterplot(data=df, y='total_bill', x=range(0,244), hue='is_outlier')
Using seaborn.scatterplot you can leverage the "hue" parameter to plot groups in different color. For your example the following should work
is_outlier = (df['total_bill'] >= 40)
sns.scatterplot(data=df['total_bill'], hue=is_outlier)

Plot two datasets at same position based on their index

I'm trying to plot two datasets (called Height and Temperature) on different y axes.
Both datasets have the same length.
Both datasets are linked together by a third dataset, RH.
I have tried to use matplotlib to plot the data using twiny() but I am struggling to align both datasets together on the same plot.
Here is the plot I want to align.
The horizontal black line on the figure is defined as the 0°C degree line that was found from Height and was used to test if both datasets, when plotted, would be aligned. They do not. There is a noticable difference between the black line and the 0°C tick from Temperature.
Rather than the two y axes changing independently from each other I would like to plot each index from Height and Temperature at the same y position on the plot.
Here is the code that I used to create the plot:
#Define number of subplots sharing y axis
f, ax1 = plt.subplots()
ax1.minorticks_on()
ax1.grid(which='major',axis='both',c='grey')
#Set axis parameters
ax1.set_ylabel('Height $(km)$')
ax1.set_ylim([np.nanmin(Height), np.nanmax(Height)])
#Plot RH
ax1.plot(RH, Height, label='Original', lw=0.5)
ax1.set_xlabel('RH $(\%)$')
ax2 = ax1.twinx()
ax2.plot(RH, Temperature, label='Original', lw=0.5, c='black')
ax2.set_ylabel('Temperature ($^\circ$C)')
ax2.set_ylim([np.nanmin(Temperature), np.nanmax(Temperature)])
Any help on this would be amazing. Thanks.
Maybe the atmosphere is wrong. :)
It sounds like you are trying to align the two y axes at particular values. Why are you doing this? The relationship of Height vs. Temperature is non-linear, so I think you are setting the stage for a confusing graph. Any particular line you plot can only be interpreted against one vertical axis.
If needed, I think you will be forced to "do some math" on the limits of the y axes. This link may be helpful:
align scales

Categories