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()
Related
I have three boxplot figures that I am loading using pickle and I would like to join and plot them side-by-side. It seems that the recommendation is to plot one figure to begin with and use matplotlib subplots. However, due to the nature of the data this would be difficult and it is easiest to make three separate figure files first. All three figures have the same y axis limits and the same x ticks.
How can I join them such that they are side-by-side on the same row?
The solution is to create a new figure with the layout you want, then insert the Axes from the existing figures into it. You can get the Axes from an existing figure with only one set of Axes using fig.axes[0], then insert it into a new figure by following this answer.
PS Emersons unite!
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?
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
I tried to plot multiple tasks in horizontal bars with Python.
I have timestamps on the x axis and tasks on the y axis. These tasks appear multiple times a day so I need to display many of them in one row. All together like a giant diagram with multiple tasks and gaps
Any idea how to plot this? It's enough to send me the name of the diagram. I searched but found nothing what I need. I need something similar like the attached picture
I'm working on creating a graph that represents activity over time, modelled after a chart in Sleep As Android. It's similar to a heatmap, but does not use color variation. Each column is a date, and the y axis is the full duration of the day. Whatever intervals of time where an activity occurs are blocked off with a bar. Here's what I have so far:
So far I have only been able to accomplish this by manually plotting rectangles on the figure. I loop through a list of events with dates, start times, and end times, plotting them like so:
ax.add_patch(patches.Rectangle((31*event_month + event_day, end_time), # (x,y)
0.75, # width
duration)) # height
This date handling is clearly wrong - it's just for the purpose of demonstration.
Normally when creating a histogram, I can plot using date objects directly with something like this:
fig.autofmt_xdate()
ax.fmt_xdata = matplotlib.dates.DateFormatter('%Y-%m-%d')
I'd like to be able to somehow just use the date objects directly when plotting. Is there a way to accomplish this in pyplot, or do I need to do something like converting the x axis to use POSIX time and just calculating where I put date labels?