matplotlib

Reverse the order of legend

喜你入骨 提交于 2021-02-17 18:44:39
问题 I use the following code to plot the bar graph. Need to present a legend in reverse order. How can I do it? colorsArr = plt.cm.BuPu(np.linspace(0, 0.5, len(C2))) p = numpy.empty(len(C2), dtype=object) plt.figure(figsize=(11,11)) prevBar = 0 for index in range(len(C2)): plt.bar(ind, C2[index], width, bottom=prevBar, color=colorsArr[index], label=C0[index]) prevBar = prevBar + C2[index] # positions of the x-axis ticks (center of the bars as bar labels) tick_pos = [i+(width/2) for i in ind] plt

Reverse the order of legend

陌路散爱 提交于 2021-02-17 18:43:10
问题 I use the following code to plot the bar graph. Need to present a legend in reverse order. How can I do it? colorsArr = plt.cm.BuPu(np.linspace(0, 0.5, len(C2))) p = numpy.empty(len(C2), dtype=object) plt.figure(figsize=(11,11)) prevBar = 0 for index in range(len(C2)): plt.bar(ind, C2[index], width, bottom=prevBar, color=colorsArr[index], label=C0[index]) prevBar = prevBar + C2[index] # positions of the x-axis ticks (center of the bars as bar labels) tick_pos = [i+(width/2) for i in ind] plt

Reverse the order of legend

纵饮孤独 提交于 2021-02-17 18:43:08
问题 I use the following code to plot the bar graph. Need to present a legend in reverse order. How can I do it? colorsArr = plt.cm.BuPu(np.linspace(0, 0.5, len(C2))) p = numpy.empty(len(C2), dtype=object) plt.figure(figsize=(11,11)) prevBar = 0 for index in range(len(C2)): plt.bar(ind, C2[index], width, bottom=prevBar, color=colorsArr[index], label=C0[index]) prevBar = prevBar + C2[index] # positions of the x-axis ticks (center of the bars as bar labels) tick_pos = [i+(width/2) for i in ind] plt

How do I write a Latex formula in the legend of a plot using Matplotlib inside a .py file?

匆匆过客 提交于 2021-02-17 08:34:08
问题 I am writing a script in Python (.py file) and I am using Matplotlib to plot an array. I want to add a legend with a formula to the plot, but I haven't been able to do it. I have done this before in IPython or the terminal. In this case, writing something like this: legend(ur'$The_formula$') worked perfectly. However, this doesn't work when I call my .py script from the terminal/IPython. 回答1: The easiest way is to assign the label when you plot the data, e.g.: import matplotlib.pyplot as plt

Plot an histogram with y-axis as percentage (using FuncFormatter?)

北慕城南 提交于 2021-02-17 08:30:47
问题 I have a list of data in which the numbers are between 1000 and 20 000. data = [1000, 1000, 5000, 3000, 4000, 16000, 2000] When I plot a histogram using the hist() function, the y-axis represents the number of occurrences of the values within a bin. Instead of the number of occurrences, I would like to have the percentage of occurrences. Code for the above plot: f, ax = plt.subplots(1, 1, figsize=(10,5)) ax.hist(data, bins = len(list(set(data)))) I've been looking at this post which describes

Seaborn: How to increase the font size of the labels on the axes?

余生颓废 提交于 2021-02-17 05:59:09
问题 Here's how I plot the heat map: sns.heatmap(table, annot=True, fmt='g', annot_kws={'size':24}) The thing is, size set only the font size of the numbers inside the heatmap. Which parameter I should use in annot_kws to set the font size of the labels on the axes? Thanks 回答1: You cannot change those directly in the call to heatmap , but you can instruct matplotlib to change the font size either in plt.rcParams directly, or using a context manager: uniform_data = np.random.rand(10, 12) plt.figure

Seaborn: How to increase the font size of the labels on the axes?

你。 提交于 2021-02-17 05:59:06
问题 Here's how I plot the heat map: sns.heatmap(table, annot=True, fmt='g', annot_kws={'size':24}) The thing is, size set only the font size of the numbers inside the heatmap. Which parameter I should use in annot_kws to set the font size of the labels on the axes? Thanks 回答1: You cannot change those directly in the call to heatmap , but you can instruct matplotlib to change the font size either in plt.rcParams directly, or using a context manager: uniform_data = np.random.rand(10, 12) plt.figure

How do I curve edges in networkX graph

点点圈 提交于 2021-02-17 05:45:10
问题 I had previous asked this question on how to achieve curved edges in networkX. It was working fine with my previous data, but when I updated the data and the code I'm unsure where I'm going wrong. The edges are only curving for certain nodes, and actually adding connections twice. I don't know why it's drawing the edges twice, once in a straight line and once curved. My code: import matplotlib.pyplot as plt import networkx as nx G = nx.Graph() G.add_edge("Ted", "May", weight=0.5) G.add_edge(

How to update a graph created by matplotlib in tkinter

别等时光非礼了梦想. 提交于 2021-02-17 05:45:06
问题 I have an app created by using tkinter. There is just a window in which I'm typing X and Y. Having these x and y, my app should create a graph using matplotlib. First time it works correctly, but others no. I mean, I open the app, input X and Y, click button and the app creates graph, then I input new X and Y, click button and this doesn't work, graph is the same, not new. I've searched many sites, but no one of solutions works. a part of code looks like: from tkinter import * import

pyplot.subplots: different behavior in python and jupyter notebook

故事扮演 提交于 2021-02-17 05:42:06
问题 While taking part in kaggle competition, i got some weird problem. Basically, I am trying to convert vector representation of am image to png file. It worked perfectly in iPython, code below: def drawing_to_np_prepare_data(drawing): drawing = eval(drawing) fig, ax = plt.subplots() plt.close(fig) print('[debug] ax=',ax) for x,y in drawing: ax.plot(x, y, marker='.') ax.axis('off') fig.canvas.draw() # Convert images to numpy array np_drawing = np.array(fig.canvas.renderer._renderer) print('