logo
down
shadow

What is the reason for matplotlib for printing labels multiple times?


What is the reason for matplotlib for printing labels multiple times?

Content Index :

What is the reason for matplotlib for printing labels multiple times?
Tag : python , By : wiznick
Date : January 12 2021, 09:11 PM

I hope this helps . You're plotting them all on the same figure so the labels are repeating because you are putting 3 different plots with identical labels on the same figure (so you'd see each label three times). You can see this by calling plt.show() at the end which gives you just a single figure that looks like this (I scrunched it down to fit my computer screen).
import pandas as pa
from datetime import datetime
import matplotlib.pyplot as plt



data = [['2018-10-29', 53, 'Anna Smith'],['2018-10-30', 118, 'Anna Smith'],['2018-10-31', 142, 'Anna Smith'],['2018-10-31', 7, 'Dominic Smith'],['2018-10-30', 1, 'Unknown Name'],['2018-10-29', 33, 'Jade Smith'],['2018-10-30', 103, 'Jade Smith'],['2018-10-31', 105, 'Jade Smith'],['2018-10-29', 41, 'Joanna Smith'],['2018-10-30', 169, 'Joanna Smith'],['2018-10-31', 220, 'Joanna Smith'],['2018-10-29', 31, 'John Smith'],['2018-10-30', 61, 'John Smith'],['2018-10-31', 79, 'John Smith'],['2018-10-29', 44, 'Nataly Smith'],['2018-10-30', 100, 'Nataly Smith'],['2018-10-31', 120, 'Nataly Smith'],['2018-10-30', 25, 'Sebastian Smith'],['2018-10-31', 47, 'Sebastian Smith'],['2018-10-29', 52, 'Veronica Smith'],['2018-10-30', 74, 'Veronica Smith'],['2018-10-31', 77, 'Veronica Smith']]
resultRunningTotal = pa.DataFrame(data, columns = ['date', 'runningTotal','name']) 
resultRunningTotal['date'] = pa.to_datetime(resultRunningTotal['date']).dt.date
print(type(resultRunningTotal))
print(resultRunningTotal.dtypes)

plt.figure(figsize=(24,13.5))
TuniqueDates = resultRunningTotal['date'][~resultRunningTotal.duplicated(['date'])]
dfUniqueDates = pa.DataFrame(TuniqueDates)
dfUniqueDates.sort_values(by=['date'], inplace=True, ascending=True)
startDate = min(dfUniqueDates['date'])

def savePlot (tDF, fig):
   listOfUniqueNames = tDF['name'].unique() 
   #print(tDF) #print_no_2
   for n in listOfUniqueNames:
      tDF2 = tDF[tDF.name == n]
      plt.figure(fig)
      tDF2.plot(kind='line',x='date',y='runningTotal',ax=plt.gca(),linewidth=3,label = n)

for d in dfUniqueDates['date']:
    mask = (resultRunningTotal['date'] >= startDate) & (resultRunningTotal['date'] <= d)
    tempDF5 = resultRunningTotal.loc[mask]
    fig_num = dfUniqueDates['date'].tolist().index(d)
    savePlot(tempDF5, fig_num)
    plt.savefig(str(d)+'plot.png')
plt.show()

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How do I assign multiple labels at once in matplotlib?


Tag : development , By : semicolonth
Date : March 29 2020, 07:55 AM
Hope that helps It is not possible to plot those two arrays agains each other directly (with at least version 1.1.1), therefore you must be looping over your y arrays. My advice would be to loop over the labels at the same time:
import matplotlib.pyplot as plt

x = [0, 1, 2, 3, 4]
y = [ [0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [9, 8, 7, 6, 5] ]
labels = ['foo', 'bar', 'baz']

for y_arr, label in zip(y, labels):
    plt.plot(x, y_arr, label=label)

plt.legend()
plt.show()

How to create ASP.NET labels multiple times by clicking a button multiple times


Tag : chash , By : David
Date : March 29 2020, 07:55 AM
help you fix your problem Solution 1: You are just replacing the new label with old one but not adding to existing labels that's why you are not able to see the multiple labels even when you clicked a button multiple times.
Replace this:
lbl_homeCarouselAdd.Text = strDiv.ToString();
lbl_homeCarouselAdd.Text += strDiv.ToString();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Diagnostics;
using System.Text;

namespace addlabels
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        int pressNumberOfTimes;
        Label lbl_homeCarouselAdd = new Label();
        static StringBuilder strDiv = new StringBuilder();
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void add_click(object sender, EventArgs e)
        {
            // Add the panel
            pressNumberOfTimes++;



            // Set the label's Text and ID properties.
            lbl_homeCarouselAdd.ID = "lbl_homeCarouselAdd" + pressNumberOfTimes;


            strDiv.Append(string.Format(@"<p class='style'>Hello world</p>"));

            lbl_homeCarouselAdd.Text += strDiv.ToString();


            Panel1.Controls.Add(lbl_homeCarouselAdd);
        }
    }
}

Multiple labels in Matplotlib


Tag : python , By : alchemist
Date : March 29 2020, 07:55 AM
Any of those help 'the initial state' already is a string, so you do not need to cast it again.
I do not see a syntax error for the moment, but surely you cannot set the label twice.
the_initial_state = 'the initial state {}'.format(t[0])
plt.plot(x,Pd[0],'r',label= the_initial_state) 

Matplotlib is printing the line plot twice/multiple times


Tag : python , By : amy
Date : March 29 2020, 07:55 AM
it fixes the issue This is because plotting df[1:] is plotting the entire dataframe as the x-axis.
>>> df[1:]
     Wavelength      Blue     Green       Red       NIR       Pan
1           355  0.001463  0.000800  0.000504  0.000532  0.000619
2           360  0.000866  0.000729  0.000391  0.000674  0.000361
3           365  0.000731  0.000806  0.000597  0.000847  0.000244
4           370  0.000717  0.000577  0.000328  0.000729  0.000435
5           375  0.001251  0.000842  0.000847  0.000906  0.000914
..          ...       ...       ...       ...       ...       ...
133        1015  0.002601  0.002100  0.001752  0.002007  0.149330
134        1020  0.001602  0.002040  0.002341  0.001793  0.136372
135        1025  0.001946  0.002218  0.001260  0.002754  0.118682
136        1030  0.002417  0.001376  0.000898  0.000000  0.103634
137        1035  0.001300  0.001602  0.000000  0.000000  0.089097

[137 rows x 6 columns]
>>> df['Wavelength'][1:]
1       355
2       360
3       365
4       370
5       375

133    1015
134    1020
135    1025
136    1030
137    1035
Name: Wavelength, Length: 137, dtype: int64

memory leak when printing bunch of times to a file by calling the function multiple times


Tag : c , By : pacorro2000
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com