mikedewar / d3py

a plottling library for python, based on D3
1.42k stars 202 forks source link

How to plot multiple lines #54

Closed vallettea closed 11 years ago

vallettea commented 11 years ago

Hello, thanks for this great module! I would like to know the proper technique to plot multiple line on a PandasFigure? What id the proper Data Frame and how to call it? for example: i would like to plot two lines on the same figure defined by x,y. How can i tel d3py to use a dataframe like that: x y 0 [1, 2] [10, 11] 1 [3, 4] [13, 14] thanks

mikedewar commented 11 years ago

Hi! You can just keep adding d3py.geoms.Line() to the figure. I made an example here:

https://github.com/mikedewar/d3py/blob/master/examples/d3py_multiline.py

It looks like this in my browser:

example

Let me know if this solves your issue!

vallettea commented 11 years ago

Ok thanks thats what i figured, but you need to have the whole data in you dataframe before starting to plot... don't you think that is a limitation for huge plots piece by piece?

mikedewar commented 11 years ago

Yes, it is something of a limitation. What would be a better idiom for you?

vallettea commented 11 years ago

I think the initiator of pandasfigure should not take the data as input. or at least that this attribute could be updated in a way that all the previous material needed for the plot is stored.

Why not think of matplotlib where you have a fig or ax and you add your elements (plot, scatter) with the concerned data?

However i'm not aware of the underlying difficulties and I already thank you for your initiative.

mikedewar commented 11 years ago

Can you express why the matplotlib style suits you better?

I also find matplotlib very natural, having grown up with Matlab, but have generally found the ggplot style (which is what we follow a bit more closely with d3py) to be more powerful overall. I like how it forces me to think about what I'm plotting....

vallettea commented 11 years ago

I don't know ggplot but I think most of the python community is used to matplotlib so people will be more confortable taking the grip on something that reminds them of that.

matplotlib suits me beter because once you defined your plot (axis etc) you can add a plot concerning arrays x and y then change x and y and add a scatter from x, y idon't know if i'm clear

mikedewar commented 11 years ago

I understand! I'm not too worried about introducing new concepts to the python plotting community, but I think your second point has a huge amount of validity.

Would your issue be addressed by having a plot such that if you changed the data underlying the plot, then the plot changes with it?

Or, would you Iike to be able to add columns to the dataframe after the plot object has been instantiated and add those into the plot?

Thanks so much for your input on this!

vallettea commented 11 years ago

I'd Iike to be able to add columns to the dataframe after the plot object has been instantiated and add those into the plot

One think which is great about d3js that may inspire you is the ability to update certain parts of the plot without changing the others by modifying the underlying data.

I don't know if I can help but don't hezitate to ask. cheers