How to remove grid from Plotly 3D plot? - plotly-python

I am using plotly in Python to plot a sphere. And I would like to know if it's possible to remove the grid and axes, everything but the sphere basically.
Additionnally, I would also like to have my three axes as just three arrows originating from the center of my sphere.
If it's not doable in Plotly, do you know of any alternative? Again, I am coding in Python.
Many thanks in advance
Antoine
trace = [
go.Surface(
name='Map',
x=tuple(x),
y=tuple(y),
z=tuple(z),
colorscale='Viridis',
surfacecolor=c_norm,
hoverinfo='text',
opacity=1
),
go.Scatter3d(
name='Z1 source',
x=[z1_sources_coord[0,0]],
y=[z1_sources_coord[0,1]],
z=[z1_sources_coord[0,2]],
mode='markers',
marker=dict(size=3, color='red'),
opacity=1
),
go.Scatter3d(
name='Z2 source',
x=z2_sources_coord[:,0],
y=z2_sources_coord[:,1],
z=z2_sources_coord[:,2],
mode='markers',
marker=dict(size=6, color='blue'),
opacity=1
)
]
fig=go.Figure(data=trace)
fig.show()

Related

Turn off x-axis marginal distribution axes on jointplot using seaborn package

There is a similar question here, however I fail to adapt the provided solutions to my case.
I want to have a jointplot with kind=hex while removing the marginal plot of the x-axis as it contains no information. In the linked question the suggestion is to use JointGrid directly, however Seaborn then seems to to be unable to draw the hexbin plot.
joint_kws = dict(gridsize=70)
g = sns.jointplot(data=all_data, x="Minute of Hour", y="Frequency", kind="hex", joint_kws=joint_kws)
plt.ylim([49.9, 50.1])
plt.xlim([0, 60])
g.ax_joint.axvline(x=30,ymin=49, ymax=51)
plt.show()
plt.close()
How to remove the margin plot over the x-axis?
Why is the vertical line not drawn?
Also is there a way to exchange the right margin to a plot which more clearly resembles the density?
edit: Here is a sample of the dataset (33kB). Read it with pd.read_pickle("./data.pickle")
I've been fiddling with an analog problem (using a scatterplot instead of the hexbin). In the end, the solution to your first point is awkwardly simple. Just add this line :
g.ax_marg_x.remove()
Regarding your second point, I've no clue as to why no line is plotted. But a workaround seems to be to use vlines instead :
g.ax_joint.vlines(x=30, ymin=49, ymax=51)
Concerning your last point, I'm afraid I haven't understood it. If you mean increasing/reducing the margin between the subplots, you can use the space argument stated in the doc.

Extra entries ignored in axis legend

I’m trying to reproduce some plots from this video with up-to-date data and superimposing points on the lines for measures taken by governments. Using pandas for the data, and to call the plot commands.
wI have no trouble plotting the lines and appropriate legends. I then add superimposed points, for which I defined these properties:
point_opts = lambda marker, color: {'label': '', 'color': 'w', 'marker': marker, 'markeredgecolor': color, 'markeredgewidth': 3, 'linestyle': None}
I would like to only add those to the legend once, instead of once per country, hence the empty label.
I then try to modify the legend as follows:
handles, labels = ax.get_legend_handles_labels()
for props in ({**point_opts(marker, 'black'), 'label': measure} for measure, marker in points.items()):
handles.append(matplotlib.lines.Line2D([], [], **props))
labels.append(props['label'])
ax.legend(handles=handles, labels=labels)
However this does not change the axis legends (and no error messages are shown). The values seem right however. For example, if I add a second plot, on the Figure:
fig.legend(handles=handles, labels=labels, loc='center left')
I then get the result below.
Why is this happening? How can I actually modify my plot axis? Using python 3.7.3 and matplotlib 3.1.3 on OpenSuse x64, if that’s of any relevance.
Ugh alright, I’ve found it… I was, somewhere later, moving the legend around with:
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
Apparently that resets the legend content to whatever the plot commands put there, erasing andy manual additions.

Are dotted/dashed colored vectors possible in matplotlib quiver?

I am working on a project and we decided to use matplotlib.
For a polar chart we have a bunch of colored vectors which need to be recognizable from each other.
Now I have been able to get this:
Quiver add is simply:
Q.append(sub.quiver(0,y_min_max[0], real_coords[i], imag_coords[i], color=color, scale=y_min_max[1]*2, zorder=5)
But is it possible to have dashed colored vectors?
The closest answer I found is this one Plotting dashed 2D vectors with matplotlib?
Which is close but I've only managed to get colored vectors surrounded with dashed lines instead of dashed vectors
Q.append(sub.quiver(0,y_min_max[0], real_coords[i], imag_coords[i], color=color, scale=y_min_max[1]*2, zorder=5, linewidth=0.5, linestyle = '--'))
I've been experimenting with various combinations but no luck for now, any ideas?
Thanks in advance

Relocating legend from GeoPandas plot

I'm plotting a map with legends using the GeoPandas plotting function. When I plot, my legends appear in the upper right corner of the figure. Here is how it looks like:
I wanted to move the legends to the lower part of the graph. I would normally would have done something like this for a normal matplotlib plot:
fig, ax = plt.subplots(1, figsize=(4.5,10))
lima_bank_num.plot(ax=ax, column='quant_cuts', cmap='Blues', alpha=1, legend=True)
ax.legend(loc='lower left')
However, this modification is not taken into account.
This could be done using the legend_kwds argument:
df.plot(column='values', legend=True, legend_kwds={'loc': 'lower right'});
You can access the legend defined on the ax instance with ax.get_legend(). You can then update the location of the legend using the method set_bbox_to_anchor. This doesn't provide the same ease of use as the loc keyword when creating a legend from scratch, but does give control over placement. So, for your example, something like:
leg = ax.get_legend()
leg.set_bbox_to_anchor((0., 0., 0.2, 0.2))
A bit of documentation of set_bbox_to_anchor, though I don't find it extraordinarily helpful.
If you have a horizontal legend and you're trying to simply reduce the gap between the legend and plot, I recommend the colorbar approach detailed at https://gis.stackexchange.com/a/330175/32531 along with passing the pad legend_kwd argument:
legend_kwds={"orientation": "horizontal", "pad": 0.01}

PyPlot in Juno: Fixing axis height

I apologise if this has already been asked, I've searched long and hard on this site and couldn't find anything that worked. I'm using Julia, specifically the Juno IDE, and I am trying to use PyPlot to create my graphs. I wanted to set the y axis height when plotting, but leave the x axis variable. Here is the code I have been using to generate my plots
fig = figure()
ax = fig[:add_axes]
BEFE250 = (plot(s1, s2, lw=1.0, "-", color="b"))
ylabel("u(x,t)", size=20)
xlabel("t", size=20)
gcf()
which gives me
However, I need space in the top left corner as I am going to layer another picture on top in latex. So I need to set the y-axis height to between -3 and 3. However, if I set the axes height in PyPlot
fig = figure()
ax = fig[:add_axes]([0.1, 0.1, -3.0, 3.0])
BEFE250 = (plot(s1, s2, lw=1.0, "-", color="b"))
ylabel("u(x,t)", size=20)
xlabel("t", size=20)
gcf()
then it switches the orientation of the x-axis. If I set the axis height after running the plot, PyPlot puts the picture in a box in a legend off to the side of the main picture, and the main picture is empty? If someone could help me out it would be greatly appreciated.
Thanks for your help.
EDIT: Using xlim=(-10.,10.) and ylim=(-2.,12.) doesn't work either. PyPlot still adapts the axes to the data.
Try xlim(-10, 10) and ylim(-2, 12) after the plot command:
plot(s1, s2, lw=1.0, "-", color="b")
ylim(-3, 3)
Just try this, without the add_axes.
You probably also want LaTeX labels -- just add an L before the string, which gives a special LaTeX string from the LaTeXString package. You can either just add the L, or add $ inside too:
ylabel(L"u(x,t)", size=20)
ylabel(L"$u(x,t)$", size=20)
[The $ are necessary in certain circumstances that I forget.]
I'm not sure how good the PyPlot support is in Juno.
You might want to try this in IJulia.
By the way, is there a reason you want to layer on a separate figure in LaTeX? That might not be the best way to do it.