matplotlib

Gantt Chart for USGS Hydrology Data with Python?

ε祈祈猫儿з 提交于 2021-02-08 04:37:55
问题 I have a compiled a dataframe that contains USGS streamflow data at several different streamgages. Now I want to create a Gantt chart similar to this. Currently, my data has columns as site names and a date index as rows. Here is a sample of my data. The problem with the Gantt chart example I linked is that my data has gaps between the start and end dates that would normally define the horizontal time-lines. Many of the examples I found only account for the start and end date, but not missing

Set a colormap under a graph

不羁岁月 提交于 2021-02-08 04:22:11
问题 I know this is well documented, but I'm struggling to implement this in my code. I would like to shade the area under my graph with a colormap. Is it possible to have a colour, i.e. red from any points over 30, and a gradient up until that point? I am using the method fill_between, but I'm happy to change this if there is a better way to do it. def plot(sd_values): plt.figure() sd_values=np.array(sd_values) x=np.arange(len(sd_values)) plt.plot(x,sd_values, linewidth=1) plt.fill_between(x,sd

How to mark cells in matplotlib.pyplot.imshow (drawing cell borders)

ⅰ亾dé卋堺 提交于 2021-02-08 04:08:13
问题 I have a small 2d vector to display: import matplotlib.pyplot as plt import numpy as np img = np.random.rand(4,10) plt.imshow(img, cmap='Reds') As folllow: But now I want to mark a specific cell, in order to focus the reader on that cell. Because this is of specific interest... Therefore something like a border of this cell would be nice: Does someone know how to archive this with matplotlib in a convenient way? 回答1: Put a rectangle at the position of the pixel you want to highlight. import

How to mark cells in matplotlib.pyplot.imshow (drawing cell borders)

核能气质少年 提交于 2021-02-08 04:03:20
问题 I have a small 2d vector to display: import matplotlib.pyplot as plt import numpy as np img = np.random.rand(4,10) plt.imshow(img, cmap='Reds') As folllow: But now I want to mark a specific cell, in order to focus the reader on that cell. Because this is of specific interest... Therefore something like a border of this cell would be nice: Does someone know how to archive this with matplotlib in a convenient way? 回答1: Put a rectangle at the position of the pixel you want to highlight. import

How to update a graph using matplotlib

泄露秘密 提交于 2021-02-08 03:48:53
问题 I'm using Panda and matplotlib to draw graphs in Python. I would like a live updating gaph. Here is my code: import matplotlib.pyplot as plt import matplotlib.animation as animation import time import numpy as np import MySQLdb import pandas def animate(): conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="sentiment_index", use_unicode=True, charset="utf8") c = conn.cursor() query = """ SELECT t_date , score FROM mytable where t_date BETWEEN Date_SUB(NOW(), Interval 2 DAY)

How to update a graph using matplotlib

☆樱花仙子☆ 提交于 2021-02-08 03:48:52
问题 I'm using Panda and matplotlib to draw graphs in Python. I would like a live updating gaph. Here is my code: import matplotlib.pyplot as plt import matplotlib.animation as animation import time import numpy as np import MySQLdb import pandas def animate(): conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="sentiment_index", use_unicode=True, charset="utf8") c = conn.cursor() query = """ SELECT t_date , score FROM mytable where t_date BETWEEN Date_SUB(NOW(), Interval 2 DAY)

matplotlib - extracting values from contour lines

有些话、适合烂在心里 提交于 2021-02-08 03:47:40
问题 This question/answer pair shows how to extract vertices from contour plot: p = cs.collections[0].get_paths()[0] v = p.vertices x = v[:,0] y = v[:,1] But how to get the value (i.e z for an elevation model) for each path? 回答1: There's no direct way, but cs.collections is in the exact same order as cs.levels (which is the "z" values you're after). Therefore, it's easiest to do something like: lookup = dict(zip(cs.collections, cs.levels)) z = lookup[line_collection_artist] As a quick interactive

Python matplotlib trend line with string x axis labels

情到浓时终转凉″ 提交于 2021-02-08 03:01:22
问题 I'm trying to graph a set of data I have my y values as y=[129.000, 128.000, 140.000, 150.000] x=["1/2018", "2/2018", "3/2018", "4/2018"] # plot the data itself pylab.plot(x,y,‘o’) # calc the trendline (it is simply a linear fitting) z = numpy.polyfit(x, y, 1) p = numpy.poly1d(z) pylab.plot(x,p(x),“r–”) # the line equation: print “y=%.6fx+(%.6f)”%(z[0],z[1]) I keep getting: ufunc 'add' did not contain loop with signature matching type dtype ('S32') ('S32') ('S32') I have tried using epoch

How can I rotate column titles in pyplot.table?

Deadly 提交于 2021-02-08 00:25:36
问题 I'm creating a table in matplotlib, but the table headers are long strings, and the table values are numbers with only a few digits. This leaves me with two bad options: either my table is much wider than necessary, or my headers overlap. To fix this, I'd like to rotate the table headings (possibly up to 90 degrees). In other words, I want to do this in python Here's my simplified code right now: import matplotlib, numpy import matplotlib.pyplot as plt data=numpy.array([[1, 2],[3,4]])

How can I rotate column titles in pyplot.table?

╄→гoц情女王★ 提交于 2021-02-08 00:20:01
问题 I'm creating a table in matplotlib, but the table headers are long strings, and the table values are numbers with only a few digits. This leaves me with two bad options: either my table is much wider than necessary, or my headers overlap. To fix this, I'd like to rotate the table headings (possibly up to 90 degrees). In other words, I want to do this in python Here's my simplified code right now: import matplotlib, numpy import matplotlib.pyplot as plt data=numpy.array([[1, 2],[3,4]])