matplotlib

How to plot day and month

杀马特。学长 韩版系。学妹 提交于 2021-02-19 05:15:00
问题 I have a chart of a daily trend over time. The year is not relevant here and I want to show only day and month. I know you can show year and month but that is not the case. I tried to create a new variable called "Day_Month": import datetime as dt df['Day'] = df['date'].dt.day df['Month'] = df['date'].dt.month df['Day_Month'] = df['Day'].astype(str) + "-" + but it's not possible to plot it as a string nor to convert it to date type. eventually, I would like my chart to look like this: 回答1:

How to plot day and month

纵饮孤独 提交于 2021-02-19 05:14:05
问题 I have a chart of a daily trend over time. The year is not relevant here and I want to show only day and month. I know you can show year and month but that is not the case. I tried to create a new variable called "Day_Month": import datetime as dt df['Day'] = df['date'].dt.day df['Month'] = df['date'].dt.month df['Day_Month'] = df['Day'].astype(str) + "-" + but it's not possible to plot it as a string nor to convert it to date type. eventually, I would like my chart to look like this: 回答1:

Using a matplotlib button to alternate/switch between plots I created

这一生的挚爱 提交于 2021-02-19 04:36:24
问题 So I've created several charts using the matplotlib library in python 3.5, but I want to be able to have the flexibility to utilize a button to alternate between the views I created within a single window. I've been trying to experiment with an example here, but have not succeeded in doing so. I was curious in how to have the flexibility to click through different views that I created. My code is sort of organized like this: def plot1(data1, 'name1'): ... ax.plot(x,y) plt.draw() def plot2

Why is matplotlib coloring my plot with so many colors?

落花浮王杯 提交于 2021-02-19 04:30:08
问题 I am plotting multiple objects, both consisting of multiple straight lines. To do so, I use a list of colors and assign one to each object. The desired result looks like this: I am doing this with the command plt.plot , providing a start and end point, and a color. While trying to get to this result, I made a mistake, and instead of names like 'pink' , I provided values like (0, 0.75, 0) . Which resulted in this: Why does matplotlib behave this way? I would like to understand how it comes

color coding using scalar mappable in matplotlib

好久不见. 提交于 2021-02-19 04:27:17
问题 is a subplot I created using matplotlib. Is it possible to code the colors on the basis of a pre-defined range? I want to pass an additional parameter, voltage to the function drawLoadDuration and define a scale (using if-else construct?) that sets the color. Higher the voltage, darker the shade. Also, for some reason, the y-tick labels for the colorbar are not showing. Any lead is most welcome...Thanks! import matplotlib.cm from pylab import * import numpy as np f, (ax1, ax2, ax3) = plt

plotting polynomial regression in same plot as the real data

梦想的初衷 提交于 2021-02-19 04:24:15
问题 I have some snippets of code that read two csvs and plot them using matplotlib.pyplot and perform polynomial regression on the same two csvs. What I want to be able to do is plot both the data and my polynomial regression on the same graph. import matplotlib.pyplot as plt import csv import numpy as np datax=np.genfromtxt('Delta R.csv') datay=np.genfromtxt('Example R.csv') plt.title ('Test graph ') plt.xlabel('x axis') plt.ylabel('y axis ') plt.plot(datax, datay,'o-') plt.show() and my second

How to avoid pie chart labels overlapping in MatPlotLib ver.2.0.2?

蓝咒 提交于 2021-02-19 03:58:06
问题 There were a lot of questions posted regarding labels overlap for pie chart plotting. However, I couldn't find automated solution except for converting them to the legend. This solution doesn't work for me as I have a lot of values (around 60), and conversion to a legend will make the plot look very messy and unclear. So my question, if I want to label pie wedges around the pie, is the any automated solution for MatPlotLib version 2.0.2 that enables labels to have a good spacing (no

How can I improve the rotation of fraction labels in a pyplot pie chart

风流意气都作罢 提交于 2021-02-19 03:52:25
问题 I copied the following example code with a minor change. I want to rotate the fractions in a certain angle. I achived my goal but my question is if there is an easier way to rotate the fractions: import matplotlib.pyplot as plt import matplotlib # Data to plot labels = 'Python', 'C++', 'Ruby', 'Java' sizes = [215, 130, 245, 210] colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue'] explode = (0.1, 0, 0, 0) # explode 1st slice # Plot pie_properties = plt.pie(sizes, labels=labels,

matplotlib set color of legend

吃可爱长大的小学妹 提交于 2021-02-19 03:51:49
问题 I am generating a plot using matplot lib to plot many points (~a few thousand) by doing the following: labels = [] for item in items: label = item[0] labels.append(label) plt.plot(item[1][0], item[1][1], 'ro', c = colors[item], label = str(label)) And then generating a legend by doing: plt.legend([str(x) for x in np.unique(labels)]) However, for each label in the legend the corresponding color is the same (not the color in the plot). Is there any way to manually set the color for the legend.

Getting the circumcentres from a delaunay triangulation generated using matplotlib

安稳与你 提交于 2021-02-19 02:24:05
问题 If I use matplotlib to generate a delaunay triangulation for a group of points, what is the most appropraite way of getting the circumcentres of the triangles that have been geenrated? I haven't yet managed to find an obvious method in the Triangulation library to do this. 回答1: You should be able to calculate it using matplotlib.delaunay.triangulate.Triangulation : Triangulation(x, y) x, y -- the coordinates of the points as 1-D arrays of floats . . . Attributes: (all should be treated as