Plotting a connected scatter plot in Matplotlib - python

I have a pandas dataframe with two columns and around 50 rows. I want to create a scatter plot of the two columns but I also want to have the datapoints connected to each other. So I did something like this:
plt.plot(df['colA'], df['colB'], 'o-')
plt.show()
I am getting an output like this:
But I want to have data points connected to each other so as to give an ellipse circumscribing the data points. I feel like the reason I'm getting this plot is that in the dataframe that's how the datapoints are sequenced.
Is there a way to deal with this?
Any help would be appreciated!
Thanks in advance

Related

Combining two dataframes with different time intervals

I am doing a study in school about the effect of noise in a person's environment and his/her activity.
I have two dataframes with data I would like to compare. The data was recorded at the same time, but the time intervals between measurements are different. This makes it hard for me to overlay a plot and look at possible correlations.
The data frames look like this:
Volume level:
steps:
When I try to put these two dataframes in one plot with a sync timeline, the steps graph looks way smaller than the volume level graph. I have tried to plot the two graphs in multiple ways, but I keep ending up with something like this:
How about this.
This code uses multi y axis so it will help you with your problem that the graph size doesn't fit.
ax = steps_Niels_1st["steps"].plot()
ax1 = ax.twinx()
ax = volume_data_Niels_1st['size'].plot(ax=ax1)
plt.show()

Change legend number range in Altair plot

I am trying to plot time series data in a kind of "climate stripes plot" using the package Altair.
The problem is that I do not know how to change the range in the legend to standardise all my plots with the same colour range and numbers in the legend. At the moment, each time I plot something the legend adapts to the range of the data.
I think the problem is with the "domain" property, maybe is not in the correct place ?
Thank you for your help :)
This is the code for the plot :
chart=alt.Chart(source).mark_rect().encode(
x=('day:O'),
y='subasins:N',
color=alt.Color('90%:Q',legend=alt.Legend(title='CH4'), bin=alt.Bin(maxbins=20),
scale=alt.Scale(scheme='blueorange'),domain=[1830,2000])
).properties(width=100).facet(column=alt.Column('month'))
chart.show()
Plots that I get now with different scales in the legend
You're using the right approach with domain, it just needs to be put inside alt.Scale:
scale=alt.Scale(scheme='blueorange', domain=[1830, 2000])
When you're using a bin transform, one way to ensure the scale is consistent is to specify the bin extent:
bin=alt.Bin(maxbins=20, extent=[1830, 2000])

3D plot of 2D pandas data frame - z-axis limits, interactivity

I Posted this question about 3D plots of data frames:
3D plot of 2d Pandas data frame
and the user referred me very very helfully to this:
Plotting Pandas Crosstab Dataframe into 3D bar chart
It use useful and the code worked in principle, but it lookes like a mess (see image below) for several reasons:
I have huge number of values to plot (470 or so, along the y-axis) so perhaps a bar chart is not the best way (I am going for a histogram kind of look, so I assumed very narrow bars would be suitable)
my counts (z axis) do not give almost any information, because the differences I need to see are from 100 to the max value
how can I make the 3D plot that shows up interactive? (being able to rotate etc) - I have seen it done in blogs/videos but sure if it's something on Tools -> Preferences that I can't find
So re: the second issue, simple enough, I tried to just change the limits of the zbar as I would for a 2D Plot, by incorporating:
ax.set_zlim([110,150])
just before the axis labels, but obviously this is the wrong way:
SO do I have to limit the values from the original data set (i.e. filter out <110), or is there a way to do this from the plot?

Multi color -Time series scatter plot in python

I'm a newbie to python. I have time series data for which I need a scatter plot.
I basically want the normal and abnormal tags to have different colors. See below images of the data and plot:
Actual data
Expected rearrangement in Data
Expected Plot
I'll be very thankful for any leads in this!
Thanks in advance!
You can use matplotlib.pyplot's scatter
import matplotlib.pyplot as plt
plt.scatter('#normal_TimestampColumn', '#normalColumn', facecolors='b')
plt.scatter('#abnormal_timestampColumn', '#abnormalColumn', facecolors='orange')

Plot separate histograms from dataframe python

I have a data frame table "pandastable3" that looks like this:
I would like to plot histograms of values for all the columns separately, but so far I am able to get only a single figure containing all the plots together with this to plot the first 3 columns:
pandastable3.hist(layout=(1,2,3))
But I am not sure I am doing that correctly as I cannot visualize anything.
I suppose diff() gives different plots for each column:
pandastable3.diff().hist()

Categories

Resources