How to scale a scatterplot in matplotlib - python

I want to plot a lot of point in a scatterplot which form a trajectory.
If I plot it with plt.scatter(). The scatterplot shows the outtake where my actual trajectory is.
What I want to plot is a scatterplot of a fixed scale/shape, lets say x from -3 to 12 and y from -3 to 12, independent of the location of the final points/trajectory.
Thanks for your help,
seller_basti

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.

Turn data-labels in Plotly Polar Plot

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!

how to use plt.yscale('log') for specific values between 0 and 1?

I need to plot a logarithmic y-axis between 0 and 1 like the graph in the picture.
I need the points on the y-axis to be [0.005,0.010,0.050,0.100,0.500,1] like the graph in the picture. how can I choose which values will show on the axis?
use plt.yscale('log') to make logarithmic scale and plt.axis([1,10000,0.004,1]) for plot borders
use plt.yticks([0.005,0.010,0.050,0.100,0.500,1],[0.005,0.010,0.050,0.100,0.500,1]) to choose the values that will show
plt.yticks([points],[names])

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

how to add space in Y axis matplotlib

I've got a simple plot in matplotlib. Every time that I plot a data, the graph render an exact Y axis to my plot. What I want is to add some space or allowance on my Y-axis. My maximum value in plot is 5
I want my graph to show at least up to 6 or 10 on it's Y-axis.
How ?
Thanks

Categories